8166057: [testbug] CoreThreadTimeOut still uses hardcoded timeout
authordl
Fri, 23 Sep 2016 13:18:22 -0700
changeset 41129 e54fb9880260
parent 41128 0dfc0bc2196c
child 41130 2004bf22423f
8166057: [testbug] CoreThreadTimeOut still uses hardcoded timeout Reviewed-by: martin, chegar, shade
jdk/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java
--- a/jdk/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java	Fri Sep 23 13:14:14 2016 -0700
+++ b/jdk/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java	Fri Sep 23 13:18:22 2016 -0700
@@ -83,15 +83,18 @@
         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));