Skip to content

Instantly share code, notes, and snippets.

@tadas-subonis
Created April 23, 2013 20:29
Show Gist options
  • Save tadas-subonis/5447112 to your computer and use it in GitHub Desktop.
Save tadas-subonis/5447112 to your computer and use it in GitHub Desktop.
void shouldRemoveThreadsAfterCoreThreadTimeoutPeriod() throws Throwable {
ThreadPoolExecutor tpe = prepareTestThreadPool(threadCount, timeoutMillis);
long t0 = System.nanoTime();
for (int i = 0; i < threadCount; i++)
tpe.submit(new Runnable() { public void run() {}});
int count = countExecutorThreads();
if (millisElapsedSince(t0) < timeoutMillis)
assertEquals(count, threadCount);
while (countExecutorThreads() > 0 &&
millisElapsedSince(t0) < 10 * 1000);
assertEquals(countExecutorThreads(), 0);
tpe.shutdown();
assertTrue(tpe.allowsCoreThreadTimeOut());
assertTrue(tpe.awaitTermination(10, TimeUnit.SECONDS));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment