1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
631 |
|
} |
632 |
|
|
633 |
|
/** |
634 |
+ |
* Waits up to LONG_DELAY_MS for the given thread to enter a wait |
635 |
+ |
* state: BLOCKED, WAITING, or TIMED_WAITING. |
636 |
+ |
*/ |
637 |
+ |
void waitForThreadToEnterWaitState(Thread thread) { |
638 |
+ |
waitForThreadToEnterWaitState(thread, LONG_DELAY_MS); |
639 |
+ |
} |
640 |
+ |
|
641 |
+ |
/** |
642 |
|
* Returns the number of milliseconds since time given by |
643 |
|
* startNanoTime, which must have been previously returned from a |
644 |
|
* call to {@link System.nanoTime()}. |
675 |
|
} |
676 |
|
} |
677 |
|
|
678 |
+ |
/** |
679 |
+ |
* Waits for LONG_DELAY_MS milliseconds for the thread to |
680 |
+ |
* terminate (using {@link Thread#join(long)}), else interrupts |
681 |
+ |
* the thread (in the hope that it may terminate later) and fails. |
682 |
+ |
*/ |
683 |
+ |
void awaitTermination(Thread t) { |
684 |
+ |
awaitTermination(t, LONG_DELAY_MS); |
685 |
+ |
} |
686 |
+ |
|
687 |
|
// Some convenient Runnable classes |
688 |
|
|
689 |
|
public abstract class CheckedRunnable implements Runnable { |
806 |
|
}}; |
807 |
|
} |
808 |
|
|
809 |
+ |
public Runnable awaiter(final CountDownLatch latch) { |
810 |
+ |
return new CheckedRunnable() { |
811 |
+ |
public void realRun() throws InterruptedException { |
812 |
+ |
latch.await(); |
813 |
+ |
}}; |
814 |
+ |
} |
815 |
+ |
|
816 |
|
public static class NPETask implements Callable<String> { |
817 |
|
public String call() { throw new NullPointerException(); } |
818 |
|
} |