--- jsr166/src/test/tck/JSR166TestCase.java 2010/10/04 05:45:19 1.57 +++ jsr166/src/test/tck/JSR166TestCase.java 2010/10/06 02:58:04 1.59 @@ -534,7 +534,7 @@ public class JSR166TestCase extends Test } /** - * Sleep until the timeout has elapsed, or interrupted. + * Sleeps until the timeout has elapsed, or interrupted. * Does NOT throw InterruptedException. */ void sleepTillInterrupted(long timeoutMillis) { @@ -544,14 +544,33 @@ public class JSR166TestCase extends Test } /** - * Returns a new started Thread running the given runnable. + * Returns a new started daemon Thread running the given runnable. */ Thread newStartedThread(Runnable runnable) { Thread t = new Thread(runnable); + t.setDaemon(true); t.start(); return t; } + /** + * Waits for the specified time (in milliseconds) for the thread + * to terminate (using {@link Thread#join(long)}), else interrupts + * the thread (in the hope that it may terminate later) and fails. + */ + void awaitTermination(Thread t, long timeoutMillis) { + try { + t.join(timeoutMillis); + } catch (InterruptedException ie) { + threadUnexpectedException(ie); + } finally { + if (t.isAlive()) { + t.interrupt(); + fail("Test timed out"); + } + } + } + // Some convenient Runnable classes public abstract class CheckedRunnable implements Runnable {