Skip to content

Instantly share code, notes, and snippets.

@Groostav
Last active July 1, 2017 22:37
Show Gist options
  • Save Groostav/600edf739a39cbbb33cbd64ad385d621 to your computer and use it in GitHub Desktop.
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.
@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