< prev index next >

test/jdk/java/util/concurrent/FutureTask/DoneTimedGetLoops.java

Print this page
8225490: Miscellaneous changes imported from jsr166 CVS 2019-09
Reviewed-by: martin, alanb

@@ -31,23 +31,26 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 /*
  * @test
+ * @library /test/lib
  * @run main DoneTimedGetLoops 300
  * @summary isDone returning true guarantees that subsequent timed get
  * will never throw TimeoutException.
  */
 
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.FutureTask;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
+import jdk.test.lib.Utils;
 
 @SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
 public class DoneTimedGetLoops {
-    final long testDurationMillisDefault = 10L * 1000L;
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
+    final long testDurationMillisDefault = 10_000L;
     final long testDurationMillis;
 
     static class PublicFutureTask extends FutureTask<Boolean> {
         static final Runnable noop = new Runnable() { public void run() {} };
         PublicFutureTask() { super(noop, null); }

@@ -61,11 +64,10 @@
     }
 
     void test(String[] args) throws Throwable {
         final long testDurationNanos = testDurationMillis * 1000L * 1000L;
         final long quittingTimeNanos = System.nanoTime() + testDurationNanos;
-        final long timeoutMillis = 10L * 1000L;
 
         final AtomicReference<PublicFutureTask> normalRef
             = new AtomicReference<>();
         final AtomicReference<PublicFutureTask> abnormalRef
             = new AtomicReference<>();

@@ -134,17 +136,17 @@
         for (Thread thread : new Thread[] {
                  setter,
                  setterException,
                  doneTimedGetNormal,
                  doneTimedGetAbnormal }) {
-            thread.join(timeoutMillis + testDurationMillis);
+            thread.join(LONG_DELAY_MS + testDurationMillis);
             if (thread.isAlive()) {
                 System.err.printf("Hung thread: %s%n", thread.getName());
                 failed++;
                 for (StackTraceElement e : thread.getStackTrace())
                     System.err.println(e);
-                thread.join(timeoutMillis);
+                thread.join(LONG_DELAY_MS);
             }
         }
     }
 
     //--------------------- Infrastructure ---------------------------
< prev index next >