590 |
* CancellationException |
* CancellationException |
591 |
*/ |
*/ |
592 |
public void testTimedGet_Cancellation() { |
public void testTimedGet_Cancellation() { |
593 |
for (final boolean mayInterruptIfRunning : |
testTimedGet_Cancellation(false); |
594 |
new boolean[] { true, false }) { |
} |
595 |
|
public void testTimedGet_Cancellation_interrupt() { |
596 |
|
testTimedGet_Cancellation(true); |
597 |
|
} |
598 |
|
public void testTimedGet_Cancellation(final boolean mayInterruptIfRunning) { |
599 |
final CountDownLatch pleaseCancel = new CountDownLatch(3); |
final CountDownLatch pleaseCancel = new CountDownLatch(3); |
600 |
final CountDownLatch cancelled = new CountDownLatch(1); |
final CountDownLatch cancelled = new CountDownLatch(1); |
601 |
final PublicFutureTask task = |
final Callable<Object> callable = |
602 |
new PublicFutureTask(new CheckedCallable<Object>() { |
new CheckedCallable<Object>() { |
603 |
public Object realCall() throws InterruptedException { |
public Object realCall() throws InterruptedException { |
604 |
pleaseCancel.countDown(); |
pleaseCancel.countDown(); |
605 |
if (mayInterruptIfRunning) { |
if (mayInterruptIfRunning) { |
610 |
await(cancelled); |
await(cancelled); |
611 |
} |
} |
612 |
return two; |
return two; |
613 |
}}); |
}}; |
614 |
|
final PublicFutureTask task = new PublicFutureTask(callable); |
615 |
|
|
616 |
Thread t1 = new ThreadShouldThrow(CancellationException.class) { |
Thread t1 = new ThreadShouldThrow(CancellationException.class) { |
617 |
public void realRun() throws Exception { |
public void realRun() throws Exception { |
640 |
tryToConfuseDoneTask(task); |
tryToConfuseDoneTask(task); |
641 |
checkCancelled(task); |
checkCancelled(task); |
642 |
} |
} |
|
} |
|
643 |
|
|
644 |
/** |
/** |
645 |
* A runtime exception in task causes get to throw ExecutionException |
* A runtime exception in task causes get to throw ExecutionException |