changeset 15696:3f11647c40cd

8166057: [testbug] CoreThreadTimeOut still uses hardcoded timeout Reviewed-by: martin, chegar, shade
author dl
date Fri, 23 Sep 2016 13:18:22 -0700
parents 926c7f71ed16
children fded5722642e
files test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java
diffstat 1 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java	Fri Sep 23 13:14:14 2016 -0700
+++ b/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));