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.

The following example illustrates the use of the Futuretask together with the Callable.
It reverses the submitted string slowly at a rate of one char per second. In the mean time, the main thread keeps polling to see if the task is completed.

Example of FutureTask

See Also

More Examples on Java



Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.