9 |
|
/** |
10 |
|
* A cancellable asynchronous computation. |
11 |
|
* |
12 |
< |
* <p>Provides methods to start and cancel the computation, query to see if |
13 |
< |
* the computation is complete, and retrieve the result of the computation. |
14 |
< |
* The result can only be retrieved when the computation has completed; |
15 |
< |
* the <tt>get</tt> method will block if the computation has not yet completed. |
16 |
< |
* Once the computation is completed, the result cannot be changed, nor can the |
17 |
< |
* computation be restarted or cancelled. |
12 |
> |
* <p><tt>FutureTask</tt> provides methods to start and cancel the |
13 |
> |
* computation, query to see if the computation is complete, and |
14 |
> |
* retrieve the result of the computation. The result can only be |
15 |
> |
* retrieved when the computation has completed; the <tt>get</tt> |
16 |
> |
* method will block if the computation has not yet completed. Once |
17 |
> |
* the computation is completed, the result cannot be changed, nor can |
18 |
> |
* the computation be restarted or cancelled. |
19 |
|
* |
20 |
|
* <p>Because <tt>FutureTask</tt> implements <tt>Runnable</tt>, a |
21 |
|
* <tt>FutureTask</tt> can be submitted to an {@link Executor} for |
35 |
|
* @spec JSR-166 |
36 |
|
* @revised $Date$ |
37 |
|
* @editor $Author$ |
38 |
+ |
* @author Doug Lea |
39 |
|
*/ |
40 |
|
public class FutureTask<V> extends CancellableTask implements Cancellable, Future<V>, Runnable { |
41 |
|
|
79 |
|
* @return the computed result |
80 |
|
* @throws CancellationException if task producing this value was |
81 |
|
* cancelled before completion |
82 |
< |
* @throws ExecutionException if the underlying computation threw an exception |
83 |
< |
* @throws InterruptedException if current thread was interrupted while waiting |
82 |
> |
* @throws ExecutionException if the underlying computation threw |
83 |
> |
* an exception |
84 |
> |
* @throws InterruptedException if current thread was interrupted |
85 |
> |
* while waiting |
86 |
|
*/ |
87 |
|
public V get() throws InterruptedException, ExecutionException { |
88 |
|
return ((InnerCancellableFuture<V>)getRunnable()).get(); |
95 |
|
* @param timeout the maximum time to wait |
96 |
|
* @param unit the time unit of the timeout argument |
97 |
|
* @return value of this task |
98 |
< |
* @throws CancellationException if task producing this value was cancelled before completion |
99 |
< |
* @throws ExecutionException if the underlying computation |
100 |
< |
* threw an exception. |
101 |
< |
* @throws InterruptedException if current thread was interrupted while waiting |
98 |
> |
* @throws CancellationException if task producing this value was |
99 |
> |
* cancelled before completion |
100 |
> |
* @throws ExecutionException if the underlying computation threw |
101 |
> |
* an exception. |
102 |
> |
* @throws InterruptedException if current thread was interrupted |
103 |
> |
* while waiting |
104 |
|
* @throws TimeoutException if the wait timed out |
105 |
|
*/ |
106 |
|
public V get(long timeout, TimeUnit unit) |