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
methods will block if the computation has not yet completed. Once the computation has completed, the computation cannot be restarted or cancelled (unless the computation is invoked using runAndReset()
).
一个可被取消的异步计算。这个类提供了对Future基本的实现,包含启动、取消计算,查询计算是否完成并且获得计算结果。结果只能在计算完成后获取,如果计算仍未结束,get方法将会被阻塞。一旦计算完毕了,该计算将无法重启或取消(除非使用runAndReset()重启计算)。
A FutureTask
can be used to wrap a Callable
or Runnable
object. Because FutureTask
implements Runnable
, aFutureTask
can be submitted to an Executor
for execution.
一个FutureTask可以用来包含一个Callable和Runnable对象。因为FutureTask实现了Runnable,一个FutureTask可以提交各给一个Executor用来执行。
In addition to serving as a standalone class, this class provides protected
functionality that may be useful when creating customized task classes.
除了作为一个独立的类,其还提供protected方法以便在创建自定义的task类时有用。