FutureTaskV


FutureTask<V> java.util.concurrent

Java 5.0 runnable

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  ( );  // Methods Implementing Runnable  public void  run  ( );  // Protected Instance Methods  protected void  done  ( );  empty  protected boolean  runAndReset  ( );        protected void  set  (V  v  );        protected void  setException  (Throwable  t  );   } 



Java In A Nutshell
Java In A Nutshell, 5th Edition
ISBN: 0596007736
EAN: 2147483647
Year: 2004
Pages: 1220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net