657 |
|
public static long MEDIUM_DELAY_MS; |
658 |
|
public static long LONG_DELAY_MS; |
659 |
|
|
660 |
+ |
/** |
661 |
+ |
* A delay significantly longer than LONG_DELAY_MS. |
662 |
+ |
* Use this in a thread that is waited for via awaitTermination(Thread). |
663 |
+ |
*/ |
664 |
+ |
public static long LONGER_DELAY_MS; |
665 |
+ |
|
666 |
|
private static final long RANDOM_TIMEOUT; |
667 |
|
private static final long RANDOM_EXPIRED_TIMEOUT; |
668 |
|
private static final TimeUnit RANDOM_TIMEUNIT; |
722 |
|
SMALL_DELAY_MS = SHORT_DELAY_MS * 5; |
723 |
|
MEDIUM_DELAY_MS = SHORT_DELAY_MS * 10; |
724 |
|
LONG_DELAY_MS = SHORT_DELAY_MS * 200; |
725 |
+ |
LONGER_DELAY_MS = 2 * LONG_DELAY_MS; |
726 |
|
} |
727 |
|
|
728 |
|
private static final long TIMEOUT_DELAY_MS |
1457 |
|
* to terminate (using {@link Thread#join(long)}), else interrupts |
1458 |
|
* the thread (in the hope that it may terminate later) and fails. |
1459 |
|
*/ |
1460 |
< |
void awaitTermination(Thread t, long timeoutMillis) { |
1460 |
> |
void awaitTermination(Thread thread, long timeoutMillis) { |
1461 |
|
try { |
1462 |
< |
t.join(timeoutMillis); |
1462 |
> |
thread.join(timeoutMillis); |
1463 |
|
} catch (InterruptedException fail) { |
1464 |
|
threadUnexpectedException(fail); |
1465 |
|
} |
1466 |
< |
Thread.State state; |
1467 |
< |
if ((state = t.getState()) != Thread.State.TERMINATED) { |
1468 |
< |
t.interrupt(); |
1469 |
< |
threadFail("timed out waiting for thread to terminate; " |
1470 |
< |
+ "state=" + state); |
1466 |
> |
if (thread.getState() != Thread.State.TERMINATED) { |
1467 |
> |
String detail = String.format( |
1468 |
> |
"timed out waiting for thread to terminate, thread=%s, state=%s" , |
1469 |
> |
thread, thread.getState()); |
1470 |
> |
try { |
1471 |
> |
threadFail(detail); |
1472 |
> |
} finally { |
1473 |
> |
// Interrupt thread __after__ having reported its stack trace |
1474 |
> |
thread.interrupt(); |
1475 |
> |
} |
1476 |
|
} |
1477 |
|
} |
1478 |
|
|