--- jsr166/src/test/tck/JSR166TestCase.java 2015/10/04 03:49:33 1.161 +++ jsr166/src/test/tck/JSR166TestCase.java 2015/10/04 18:40:57 1.164 @@ -590,7 +590,7 @@ public class JSR166TestCase extends Test } /** - * Finds missing try { ... } finally { joinPool(e); } + * Finds missing PoolCleaners */ void checkForkJoinPoolThreadLeaks() throws InterruptedException { Thread[] survivors = new Thread[7]; @@ -749,22 +749,20 @@ public class JSR166TestCase extends Test /** * Delays, via Thread.sleep, for the given millisecond delay, but * if the sleep is shorter than specified, may re-sleep or yield - * until time elapses. + * until time elapses. Ensures that the given time, as measured + * by System.nanoTime(), has elapsed. */ static void delay(long millis) throws InterruptedException { - long startTime = System.nanoTime(); - long ns = millis * 1000 * 1000; - for (;;) { + long nanos = millis * (1000 * 1000); + final long wakeupTime = System.nanoTime() + nanos; + do { if (millis > 0L) Thread.sleep(millis); else // too short to sleep Thread.yield(); - long d = ns - (System.nanoTime() - startTime); - if (d > 0L) - millis = d / (1000 * 1000); - else - break; - } + nanos = wakeupTime - System.nanoTime(); + millis = nanos / (1000 * 1000); + } while (nanos >= 0L); } /** @@ -1319,9 +1317,9 @@ public class JSR166TestCase extends Test } class LatchAwaiter extends CheckedRunnable { - final static int NEW = 0; - final static int RUNNING = 1; - final static int DONE = 2; + static final int NEW = 0; + static final int RUNNING = 1; + static final int DONE = 2; final CountDownLatch latch; int state = NEW; LatchAwaiter(CountDownLatch latch) { this.latch = latch; } @@ -1331,7 +1329,7 @@ public class JSR166TestCase extends Test state = 2; } } - + public LatchAwaiter awaiter(CountDownLatch latch) { return new LatchAwaiter(latch); }