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.86 by jsr166, Sun Jun 19 06:06:24 2011 UTC vs.
Revision 1.87 by jsr166, Sun Jun 19 07:46:18 2011 UTC

# Line 217 | Line 217 | public class FutureTask<V> implements Ru
217      }
218  
219      public void run() {
220 <        if (state == NEW &&
221 <            UNSAFE.compareAndSwapObject(this, runnerOffset,
222 <                                        null, Thread.currentThread())) {
220 >        if (state != NEW ||
221 >            !UNSAFE.compareAndSwapObject(this, runnerOffset,
222 >                                         null, Thread.currentThread()))
223 >            return;
224 >        try {
225              Callable<V> c = callable;
226              if (c != null && state == NEW) {
227 <                V result = null;
226 <                boolean ran = false;
227 >                V result;
228                  try {
229                      result = c.call();
229                    ran = true;
230                  } catch (Throwable ex) {
231                      setException(ex);
232 +                    return;
233                  }
234 <                if (ran)
234 <                    set(result);
234 >                set(result);
235              }
236 +        } finally {
237              runner = null;
238              int s = state;
239              if (s >= INTERRUPTING)
# Line 250 | Line 251 | public class FutureTask<V> implements Ru
251       * @return true if successfully run and reset
252       */
253      protected boolean runAndReset() {
254 <        boolean rerun = false; // true if this task can be re-run
255 <        if (state == NEW &&
256 <            UNSAFE.compareAndSwapObject(this, runnerOffset,
257 <                                        null, Thread.currentThread())) {
254 >        if (state != NEW ||
255 >            !UNSAFE.compareAndSwapObject(this, runnerOffset,
256 >                                         null, Thread.currentThread()))
257 >            return false;
258 >        try {
259              Callable<V> c = callable;
260              if (c != null && state == NEW) {
261                  try {
262                      c.call(); // don't set result
263 <                    rerun = true;
263 >                    return state == NEW;
264                  } catch (Throwable ex) {
265                      setException(ex);
266                  }
267              }
268 +            return false;
269 +        } finally {
270              runner = null;
271              int s = state;
272 <            if (s != NEW) {
273 <                rerun = false;
270 <                if (s >= INTERRUPTING)
271 <                    handlePossibleCancellationInterrupt(s);
272 <            }
272 >            if (s >= INTERRUPTING)
273 >                handlePossibleCancellationInterrupt(s);
274          }
274        return rerun;
275      }
276  
277      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines