| Java 2 Platform Standard Ed. 5.0 | ||||||||||
java.lang.Objectjava.util.concurrent.FutureTask<V>
V - The result type returned by this FutureTask'sget methodpublic classFutureTask<V>
A cancellable asynchronous computation. This class provides a base implementation ofFuture, 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; theget method will block if the computation has not yet completed. Once the computation has completed, the computation cannot be restarted or cancelled.
AFutureTask can be used to wrap aCallable orRunnable object. BecauseFutureTask implementsRunnable, aFutureTask can be submitted to anExecutor for execution.
In addition to serving as a standalone class, this class providesprotected functionality that may be useful when creating customized task classes.
FutureTask(Callable<V> callable)Creates aFutureTask that will upon running, execute the givenCallable. | |
FutureTask(Runnable runnable,V result)Creates aFutureTask that will upon running, execute the givenRunnable, and arrange thatget will return the given result on successful completion. | |
cancel(boolean mayInterruptIfRunning)Attempts to cancel execution of this task. | |
done()Protected method invoked when this task transitions to stateisDone (whether normally or via cancellation). | |
get()Waits if necessary for the computation to complete, and then retrieves its result. | |
get(long timeout,TimeUnit unit)Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available. | |
isCancelled()Returnstrue if this task was cancelled before it completed normally. | |
isDone()Returnstrue if this task completed. | |
run()Sets this Future to the result of computation unless it has been cancelled. | |
runAndReset()Executes the computation without setting its result, and then resets this Future to initial state, failing to do so if the computation encounters an exception or is cancelled. | |
set(V v)Sets the result of this Future to the given value unless this future has already been set or has been cancelled. | |
setException(Throwable t)Causes this future to report anExecutionException with the given throwable as its cause, unless this Future has already been set or has been cancelled. | |
| Methods inherited from class java.lang.Object |
|---|
clone,equals,finalize,getClass,hashCode,notify,notifyAll,toString,wait,wait,wait |
publicFutureTask(Callable<V> callable)
callable - the callable taskNullPointerException - if callable is nullpublicFutureTask(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 constructions of the form:Future<?> f = new FutureTask<Object>(runnable, null)NullPointerException - if runnable is nullpublic booleanisCancelled()
FutureisCancelled in interfaceFuture<V>public booleanisDone()
FutureisDone in interfaceFuture<V>public booleancancel(boolean mayInterruptIfRunning)
Futurecancel in interfaceFuture<V>mayInterruptIfRunning -true if the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to completepublicVget() throwsInterruptedException,ExecutionException
Futureget in interfaceFuture<V>InterruptedException - if the current thread was interrupted while waitingExecutionException - if the computation threw an exceptionpublicVget(long timeout,TimeUnit unit) throwsInterruptedException,ExecutionException,TimeoutException
Futureget in interfaceFuture<V>timeout - the maximum time to waitunit - the time unit of the timeout argumentInterruptedException - if the current thread was interrupted while waitingExecutionException - if the computation threw an exceptionTimeoutException - if the wait timed outprotected voiddone()
protected voidset(V v)
v - the valueprotected voidsetException(Throwable t)
t - the cause of failure.public voidrun()
run in interfaceRunnableThread.run()protected booleanrunAndReset()
| Java 2 Platform Standard Ed. 5.0 | ||||||||||