ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/FutureTask.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/FutureTask.java (file contents):
Revision 1.14 by dl, Thu Dec 4 21:39:09 2003 UTC vs.
Revision 1.15 by dl, Fri Dec 5 11:57:52 2003 UTC

# Line 57 | Line 57 | public class FutureTask<V> implements Fu
57       * will be null.
58       */
59  
60 <    /** The runnable, if non-null, then callable is null */
61 <    final Runnable runnable;
62 <    /** The callable, if non-null, then runnable is null */
63 <    final Callable<V> callable;
60 >    /** The runnable; if non-null, then callable is null */
61 >    private final Runnable runnable;
62 >    /** The callable; if non-null, then runnable is null */
63 >    private final Callable<V> callable;
64  
65      /** The result to return from get() */
66      private V result;
# Line 95 | Line 95 | public class FutureTask<V> implements Fu
95       * <tt>Boolean.TRUE</tt>.
96       * @throws NullPointerException if runnable is null
97       */
98 <    public FutureTask(final Runnable runnable, final V result) {
98 >    public FutureTask(Runnable runnable, V result) {
99          if (runnable == null)
100              throw new NullPointerException();
101          this.runnable = runnable;
# Line 297 | Line 297 | public class FutureTask<V> implements Fu
297      }
298  
299      /**
300 +     * Sets this Future to the results of computation and then resets
301 +     * to initial state. This may be useful for tasks that must
302 +     * execute more than once.
303 +     */
304 +    protected void runAndReset() {
305 +        if (setRunning()) {
306 +            try {
307 +                try {
308 +                    if (runnable != null)
309 +                        runnable.run();
310 +                    else if (callable != null)
311 +                        set(callable.call());
312 +                } catch(Throwable ex) {
313 +                    setException(ex);
314 +                }
315 +            } finally {
316 +                reset();
317 +            }
318 +        }
319 +    }
320 +
321 +    /**
322       * Protected method invoked when this task transitions to state
323       * <tt>isDone</tt> (whether normally or via cancellation). The
324       * default implementation does nothing.  Subclasses may override
# Line 325 | Line 347 | public class FutureTask<V> implements Fu
347              lock.unlock();
348          }
349      }
328 }
329
330
331
332
333
334
335
350  
351 +    /**
352 +     * Return the <tt>Runnable</tt> or <tt>Callable</tt> used
353 +     * in the constructor for this <tt>Future</tt>.
354 +     * @return the task
355 +     */
356 +    protected Object getTask() {
357 +        if (runnable != null)
358 +            return runnable;
359 +        else
360 +            return callable;
361 +    }
362  
363 + }
364  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines