--- jsr166/src/test/tck/JSR166TestCase.java 2010/10/21 23:22:49 1.65 +++ jsr166/src/test/tck/JSR166TestCase.java 2010/10/29 06:58:56 1.67 @@ -11,6 +11,7 @@ import java.util.PropertyPermission; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReference; import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static java.util.concurrent.TimeUnit.NANOSECONDS; import java.security.CodeSource; import java.security.Permission; import java.security.PermissionCollection; @@ -615,14 +616,28 @@ public class JSR166TestCase extends Test Thread.State s = thread.getState(); if (s == Thread.State.BLOCKED || s == Thread.State.WAITING || - s == Thread.State.TIMED_WAITING || - System.nanoTime() - t0 > timeoutNanos) + s == Thread.State.TIMED_WAITING) return; + else if (s == Thread.State.TERMINATED) + fail("Unexpected thread termination"); + else if (System.nanoTime() - t0 > timeoutNanos) { + threadAssertTrue(thread.isAlive()); + return; + } Thread.yield(); } } /** + * Returns the number of milliseconds since time given by + * startNanoTime, which must have been previously returned from a + * call to {@link System.nanoTime()}. + */ + long millisElapsedSince(long startNanoTime) { + return NANOSECONDS.toMillis(System.nanoTime() - startNanoTime); + } + + /** * Returns a new started daemon Thread running the given runnable. */ Thread newStartedThread(Runnable runnable) {