Name
FutureTask<V>
Synopsis
This
class is
a Runnable wrapper around a
Callable object (or around another
Runnable). FutureTask is a
generic type and the type variable V
represents the return type of the wrapped Callable
object. AbstractExecutorService uses
FutureTask to convert Callable
objects passed to the submit( ) method into
Runnable objects it can pass to the
execute( ) method.
FutureTask also implements the
Future interface, which means that the
get( ) method waits for the run(
) method to complete and provides access to the result (or
exception) of the Callable’s
execution.
The protected methods set( ) and
setException( ) are invoked when the
Callable returns a value or throws an exception.
done( ) is invoked when the
Callable completes or is canceled. Subclasses can
override any of these methods to insert hooks for notification,
logging, and so on.
Figure 16-85. java.util.concurrent.FutureTask<V>
public class FutureTask<V> implements Future<V>, Runnable { // Public Constructors public FutureTask(Callable<V> callable); public FutureTask(Runnable runnable, V result); // Methods Implementing Future public boolean cancel(boolean mayInterruptIfRunning); public V get( ) throws InterruptedException, ExecutionException; public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException; public boolean isCancelled( ); public boolean isDone( ); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access