--- jsr166/src/test/tck/JSR166TestCase.java 2010/10/06 02:11:57 1.58 +++ 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) { @@ -553,6 +553,24 @@ public class JSR166TestCase extends Test 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 {