Future
java.util.concurrent.Future<V> |
Known Indirect Subclasses
|
Class Overview
A Future represents the result of an asynchronous computation. Methods are provided to check if the computation is complete, to wait for its completion, and to retrieve the result of the computation. The result can only be retrieved using methodget when the computation has completed, blocking if necessary until it is ready. Cancellation is performed by thecancel method. Additional methods are provided to determine if the task completed normally or was cancelled. Once a computation has completed, the computation cannot be cancelled. If you would like to use aFuture for the sake of cancellability but not provide a usable result, you can declare types of the formFuture<?>
and return null as a result of the underlying task.
Class Overview
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; 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
orRunnable
object. BecauseFutureTask implements Runnable, a FutureTask can be submitted to anExecutor
for execution.
In addition to serving as a standalone class, this class provides protected functionality that may be useful when creating customized task classes.
一个可取消的异步运算,这个类实现了Fututre的借口,可以开始和取消一个运算操作,判断这个操作是否已经完成了,和重新得到运算操作的结果。运算的结果仅仅在运算结束完成后被恢复,get的方法将会阻塞程序,如果这个运算操作还没有完成的话。一旦运算操作完成了,这个操作就不能重新开始或者取消了。
这个类过去常常用于包装一个Callable or Runnable 类的。因为FutureTask实现了runnable借口,一个FutureTask可以实现线程池中的execution方法。
除了是一个单独的类之外,这个类还提供了可能有之用途定制任务classed的保护功能.