From c9f268cc15689f01be36e4e8b2512166991da66b Mon Sep 17 00:00:00 2001 From: Doug Lea Date: Fri, 23 Sep 2016 13:18:22 -0700 Subject: [PATCH] 8166057: [testbug] CoreThreadTimeOut still uses hardcoded timeout Reviewed-by: martin, chegar, shade --- .../ThreadPoolExecutor/CoreThreadTimeOut.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/jdk/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java b/jdk/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java index 088907cae77..a8bb4c29615 100644 --- a/jdk/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java +++ b/jdk/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java @@ -83,15 +83,18 @@ public class CoreThreadTimeOut { tpe.allowCoreThreadTimeOut(true); check(tpe.allowsCoreThreadTimeOut()); equal(countExecutorThreads(), 0); - 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) - equal(count, threadCount); + long startTime = System.nanoTime(); + for (int i = 0; i < threadCount; i++) { + tpe.submit(() -> {}); + int count = countExecutorThreads(); + if (millisElapsedSince(startTime) < timeoutMillis) + equal(count, i + 1); + } while (countExecutorThreads() > 0 && - millisElapsedSince(t0) < 10 * 1000); + millisElapsedSince(startTime) < LONG_DELAY_MS) + Thread.yield(); equal(countExecutorThreads(), 0); + check(millisElapsedSince(startTime) >= timeoutMillis); tpe.shutdown(); check(tpe.allowsCoreThreadTimeOut()); check(tpe.awaitTermination(LONG_DELAY_MS, MILLISECONDS));