|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.concurrent.CancellableTask
java.util.concurrent.FutureTask
A cancellable asynchronous computation. This class provides a base
implementation of Future, with methods to start and cancel
a computation, query to see if the computation is complete, and
retrieve the result of the computation. The result can only be
retrieved when the computation has completed; the get
method will block if the computation has not yet completed. Once
the computation has completed, the computation cannot be restarted
or cancelled.
A FutureTask can be used to wrap a Callable or
Runnable object. Because FutureTask
implements Runnable, a FutureTask can be
submitted to an Executor for execution.
| Nested Class Summary |
| Nested classes inherited from class java.util.concurrent.CancellableTask |
CancellableTask.InnerCancellableFuture<V> |
| Constructor Summary | |
FutureTask(Callable<V> callable)
Constructs a FutureTask that will upon running, execute the given Callable. |
|
FutureTask(java.lang.Runnable runnable,
V result)
Constructs a FutureTask that will upon running, execute the given Runnable, and arrange that get will return the given result on successful completion. |
|
| Method Summary | |
V |
get()
Waits if necessary for the computation to complete, and then retrieves its result. |
V |
get(long timeout,
TimeUnit unit)
Waits if necessary for at most the given time for the computation to complete, and then retrieves its result. |
protected void |
set(V v)
Sets the value of this task to the given value. |
protected void |
setException(java.lang.Throwable t)
Indicates that the computation has failed. |
| Methods inherited from class java.util.concurrent.CancellableTask |
cancel, getRunnable, isCancelled, isDone, reset, run, setCancelled, setDone, setRunnable, setRunning |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface java.util.concurrent.Cancellable |
cancel, isCancelled, isDone |
| Constructor Detail |
public FutureTask(Callable<V> callable)
callable - the callable task
java.lang.NullPointerException - if callable is null
public FutureTask(java.lang.Runnable runnable,
V result)
runnable - the runnable taskresult - the result to return on successful completion. If
you don't need a particular result, consider using
Boolean.TRUE.
java.lang.NullPointerException - if runnable is null| Method Detail |
public V get()
throws java.lang.InterruptedException,
ExecutionException
get in interface FutureCancellationException - if task producing this value was
cancelled before completion
ExecutionException - if the underlying computation threw
an exception
java.lang.InterruptedException - if current thread was interrupted
while waiting
public V get(long timeout,
TimeUnit unit)
throws java.lang.InterruptedException,
ExecutionException,
TimeoutException
get in interface Futuretimeout - the maximum time to waitunit - the time unit of the timeout argument
CancellationException - if task producing this value was
cancelled before completion
ExecutionException - if the underlying computation threw
an exception.
java.lang.InterruptedException - if current thread was interrupted
while waiting
TimeoutException - if the wait timed outprotected void set(V v)
v - the valueprotected void setException(java.lang.Throwable t)
t - the throwable
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||