131 |
|
System.out.printf("%n%s: %d%n", toString(), elapsedMillis); |
132 |
|
} |
133 |
|
} |
134 |
< |
|
134 |
> |
|
135 |
|
/** |
136 |
|
* Runs all JSR166 unit tests using junit.textui.TestRunner |
137 |
|
*/ |
605 |
|
} |
606 |
|
|
607 |
|
/** |
608 |
+ |
* Waits up to the specified number of milliseconds for the given |
609 |
+ |
* thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING. |
610 |
+ |
*/ |
611 |
+ |
void waitForThreadToEnterWaitState(Thread thread, long timeoutMillis) { |
612 |
+ |
long timeoutNanos = timeoutMillis * 1000L * 1000L; |
613 |
+ |
long t0 = System.nanoTime(); |
614 |
+ |
for (;;) { |
615 |
+ |
Thread.State s = thread.getState(); |
616 |
+ |
if (s == Thread.State.BLOCKED || |
617 |
+ |
s == Thread.State.WAITING || |
618 |
+ |
s == Thread.State.TIMED_WAITING || |
619 |
+ |
System.nanoTime() - t0 > timeoutNanos) |
620 |
+ |
return; |
621 |
+ |
Thread.yield(); |
622 |
+ |
} |
623 |
+ |
} |
624 |
+ |
|
625 |
+ |
/** |
626 |
|
* Returns a new started daemon Thread running the given runnable. |
627 |
|
*/ |
628 |
|
Thread newStartedThread(Runnable runnable) { |
764 |
|
|
765 |
|
public Callable<String> latchAwaitingStringTask(final CountDownLatch latch) { |
766 |
|
return new CheckedCallable<String>() { |
767 |
< |
public String realCall() { |
767 |
> |
protected String realCall() { |
768 |
|
try { |
769 |
|
latch.await(); |
770 |
|
} catch (InterruptedException quittingTime) {} |
825 |
|
} |
826 |
|
} |
827 |
|
|
828 |
+ |
public Runnable possiblyInterruptedRunnable(final long timeoutMillis) { |
829 |
+ |
return new CheckedRunnable() { |
830 |
+ |
protected void realRun() { |
831 |
+ |
try { |
832 |
+ |
Thread.sleep(timeoutMillis); |
833 |
+ |
} catch (InterruptedException ok) {} |
834 |
+ |
}}; |
835 |
+ |
} |
836 |
+ |
|
837 |
|
public class MediumPossiblyInterruptedRunnable extends CheckedRunnable { |
838 |
|
protected void realRun() { |
839 |
|
try { |