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.53 by jsr166, Thu Jun 22 05:23:32 2006 UTC vs.
Revision 1.54 by jsr166, Tue Jan 9 18:10:26 2007 UTC

# Line 35 | Line 35 | public class FutureTask<V> implements Ru
35      private final Sync sync;
36  
37      /**
38 <     * Creates a <tt>FutureTask</tt> that will upon running, execute the
38 >     * Creates a <tt>FutureTask</tt> that will, upon running, execute the
39       * given <tt>Callable</tt>.
40       *
41       * @param  callable the callable task
# Line 48 | Line 48 | public class FutureTask<V> implements Ru
48      }
49  
50      /**
51 <     * Creates a <tt>FutureTask</tt> that will upon running, execute the
51 >     * Creates a <tt>FutureTask</tt> that will, upon running, execute the
52       * given <tt>Runnable</tt>, and arrange that <tt>get</tt> will return the
53       * given result on successful completion.
54       *
55 <     * @param  runnable the runnable task
55 >     * @param runnable the runnable task
56       * @param result the result to return on successful completion. If
57       * you don't need a particular result, consider using
58       * constructions of the form:
# Line 160 | Line 160 | public class FutureTask<V> implements Ru
160      private final class Sync extends AbstractQueuedSynchronizer {
161          private static final long serialVersionUID = -7828117401763700385L;
162  
163 +        /** State value representing that task is ready to run */
164 +        private static final int READY     = 0;
165          /** State value representing that task is running */
166          private static final int RUNNING   = 1;
167          /** State value representing that task ran */
# Line 193 | Line 195 | public class FutureTask<V> implements Ru
195           * Implements AQS base acquire to succeed if ran or cancelled
196           */
197          protected int tryAcquireShared(int ignore) {
198 <            return innerIsDone()? 1 : -1;
198 >            return innerIsDone() ? 1 : -1;
199          }
200  
201          /**
# Line 215 | Line 217 | public class FutureTask<V> implements Ru
217  
218          V innerGet() throws InterruptedException, ExecutionException {
219              acquireSharedInterruptibly(0);
220 <            if (getState() == CANCELLED)
221 <                throw new CancellationException();
222 <            if (exception != null)
223 <                throw new ExecutionException(exception);
224 <            return result;
220 >            if (getState() == CANCELLED)
221 >                throw new CancellationException();
222 >            if (exception != null)
223 >                throw new ExecutionException(exception);
224 >            return result;
225          }
226  
227          V innerGet(long nanosTimeout) throws InterruptedException, ExecutionException, TimeoutException {
# Line 267 | Line 269 | public class FutureTask<V> implements Ru
269                  }
270                  if (compareAndSetState(s, RAN)) {
271                      exception = t;
270                    result = null;
272                      releaseShared(0);
273                      done();
274                      return;
# Line 294 | Line 295 | public class FutureTask<V> implements Ru
295          }
296  
297          void innerRun() {
298 <            if (!compareAndSetState(0, RUNNING))
298 >            if (!compareAndSetState(READY, RUNNING))
299                  return;
300              try {
301                  runner = Thread.currentThread();
302                  if (getState() == RUNNING) // recheck after setting thread
303 <                    innerSet(callable.call());
303 >                    set(callable.call());
304                  else
305                      releaseShared(0); // cancel
306              } catch (Throwable ex) {
307 <                innerSetException(ex);
307 >                setException(ex);
308              }
309          }
310  
311          boolean innerRunAndReset() {
312 <            if (!compareAndSetState(0, RUNNING))
312 >            if (!compareAndSetState(READY, RUNNING))
313                  return false;
314              try {
315                  runner = Thread.currentThread();
316                  if (getState() == RUNNING)
317                      callable.call(); // don't set result
318                  runner = null;
319 <                return compareAndSetState(RUNNING, 0);
319 >                return compareAndSetState(RUNNING, READY);
320              } catch (Throwable ex) {
321 <                innerSetException(ex);
321 >                setException(ex);
322                  return false;
323              }
324          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines