Last active
July 1, 2017 22:37
-
-
Save Groostav/600edf739a39cbbb33cbd64ad385d621 to your computer and use it in GitHub Desktop.
verification that a thread pool executor wont expire threads mid schedule or otherwise run out of threads.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test fun `when using thread pool executors should keep threads alive for new jobs`(){ | |
var callCount = 0; | |
val executor = ScheduledThreadPoolExecutor(1).apply { | |
setKeepAliveTime(1, TimeUnit.MILLISECONDS) | |
allowCoreThreadTimeOut(true) | |
} | |
System.gc() | |
executor.schedule({ callCount += 1 }, 5, TimeUnit.MILLISECONDS) | |
Thread.sleep(10) | |
System.gc() | |
executor.schedule({ callCount += 1 }, 5, TimeUnit.MILLISECONDS) | |
Thread.sleep(10) | |
System.gc() | |
assertThat(callCount).isEqualTo(2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment