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( ); ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.