src/share/classes/java/util/concurrent/FutureTask.java

Print this page




  68      * given <tt>Callable</tt>.
  69      *
  70      * @param  callable the callable task
  71      * @throws NullPointerException if callable is null
  72      */
  73     public FutureTask(Callable<V> callable) {
  74         if (callable == null)
  75             throw new NullPointerException();
  76         sync = new Sync(callable);
  77     }
  78 
  79     /**
  80      * Creates a <tt>FutureTask</tt> that will, upon running, execute the
  81      * given <tt>Runnable</tt>, and arrange that <tt>get</tt> will return the
  82      * given result on successful completion.
  83      *
  84      * @param runnable the runnable task
  85      * @param result the result to return on successful completion. If
  86      * you don't need a particular result, consider using
  87      * constructions of the form:
  88      * <tt>Future&lt;?&gt; f = new FutureTask&lt;Object&gt;(runnable, null)</tt>
  89      * @throws NullPointerException if runnable is null
  90      */
  91     public FutureTask(Runnable runnable, V result) {
  92         sync = new Sync(Executors.callable(runnable, result));
  93     }
  94 
  95     public boolean isCancelled() {
  96         return sync.innerIsCancelled();
  97     }
  98 
  99     public boolean isDone() {
 100         return sync.innerIsDone();
 101     }
 102 
 103     public boolean cancel(boolean mayInterruptIfRunning) {
 104         return sync.innerCancel(mayInterruptIfRunning);
 105     }
 106 
 107     /**
 108      * @throws CancellationException {@inheritDoc}




  68      * given <tt>Callable</tt>.
  69      *
  70      * @param  callable the callable task
  71      * @throws NullPointerException if callable is null
  72      */
  73     public FutureTask(Callable<V> callable) {
  74         if (callable == null)
  75             throw new NullPointerException();
  76         sync = new Sync(callable);
  77     }
  78 
  79     /**
  80      * Creates a <tt>FutureTask</tt> that will, upon running, execute the
  81      * given <tt>Runnable</tt>, and arrange that <tt>get</tt> will return the
  82      * given result on successful completion.
  83      *
  84      * @param runnable the runnable task
  85      * @param result the result to return on successful completion. If
  86      * you don't need a particular result, consider using
  87      * constructions of the form:
  88      * {@code Future<?> f = new FutureTask<Void>(runnable, null)}
  89      * @throws NullPointerException if runnable is null
  90      */
  91     public FutureTask(Runnable runnable, V result) {
  92         sync = new Sync(Executors.callable(runnable, result));
  93     }
  94 
  95     public boolean isCancelled() {
  96         return sync.innerIsCancelled();
  97     }
  98 
  99     public boolean isDone() {
 100         return sync.innerIsDone();
 101     }
 102 
 103     public boolean cancel(boolean mayInterruptIfRunning) {
 104         return sync.innerCancel(mayInterruptIfRunning);
 105     }
 106 
 107     /**
 108      * @throws CancellationException {@inheritDoc}