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 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
10 |
< |
import java.util.concurrent.*; |
10 |
> |
import java.util.concurrent.Callable; |
11 |
> |
import java.util.concurrent.CancellationException; |
12 |
> |
import java.util.concurrent.CountDownLatch; |
13 |
> |
import java.util.concurrent.ExecutionException; |
14 |
> |
import java.util.concurrent.Future; |
15 |
> |
import java.util.concurrent.FutureTask; |
16 |
> |
import java.util.concurrent.TimeoutException; |
17 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
18 |
|
import static java.util.concurrent.TimeUnit.SECONDS; |
19 |
|
import java.util.*; |
148 |
|
checkCancelled(task); |
149 |
|
} |
150 |
|
|
145 |
– |
|
151 |
|
/** |
152 |
|
* setting value causes get to return it |
153 |
|
*/ |
371 |
|
new FutureTask(new CheckedInterruptedCallable<Object>() { |
372 |
|
public Object realCall() throws InterruptedException { |
373 |
|
threadStarted.countDown(); |
374 |
< |
Thread.sleep(LONG_DELAY_MS); |
374 |
> |
delay(LONG_DELAY_MS); |
375 |
|
return Boolean.TRUE; |
376 |
|
}}); |
377 |
|
|
400 |
|
new FutureTask(new CheckedInterruptedCallable<Object>() { |
401 |
|
public Object realCall() throws InterruptedException { |
402 |
|
threadStarted.countDown(); |
403 |
< |
Thread.sleep(LONG_DELAY_MS); |
403 |
> |
delay(LONG_DELAY_MS); |
404 |
|
return Boolean.TRUE; |
405 |
|
}}); |
406 |
|
|
419 |
|
checkCancelled(task); |
420 |
|
} |
421 |
|
|
417 |
– |
|
422 |
|
/** |
423 |
|
* A runtime exception in task causes get to throw ExecutionException |
424 |
|
*/ |
457 |
|
} |
458 |
|
} |
459 |
|
|
456 |
– |
|
460 |
|
/** |
461 |
|
* Interrupting a waiting get causes it to throw InterruptedException |
462 |
|
*/ |
471 |
|
|
472 |
|
threadStarted.await(); |
473 |
|
t.interrupt(); |
474 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
474 |
> |
awaitTermination(t); |
475 |
|
checkNotDone(task); |
476 |
|
} |
477 |
|
|
484 |
|
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
485 |
|
public void realRun() throws Exception { |
486 |
|
threadStarted.countDown(); |
487 |
< |
task.get(LONG_DELAY_MS, MILLISECONDS); |
487 |
> |
task.get(2*LONG_DELAY_MS, MILLISECONDS); |
488 |
|
}}); |
489 |
|
|
490 |
|
threadStarted.await(); |
491 |
|
t.interrupt(); |
492 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
492 |
> |
awaitTermination(t); |
493 |
|
checkNotDone(task); |
494 |
|
} |
495 |
|
|