Changes so that we only set the running thread if we actually ARE the running thread

This commit is contained in:
Mike Jensen 2014-03-10 12:43:22 -06:00
parent 83a31314e0
commit d56087240d

View File

@ -34,21 +34,17 @@ public class FutureTask<T> implements RunnableFuture<T> {
@Override
public void run() {
// must set running thread before we change the state for cancel to work
runningThread = Thread.currentThread();
try {
if (currentState.compareAndSet(State.New, State.Running)) {
try {
result = callable.call();
} catch (Throwable t) {
failure = t;
} finally {
currentState.compareAndSet(State.Running, State.Done);
handleDone();
}
if (currentState.compareAndSet(State.New, State.Running)) {
runningThread = Thread.currentThread();
try {
result = callable.call();
} catch (Throwable t) {
failure = t;
} finally {
currentState.compareAndSet(State.Running, State.Done);
handleDone();
runningThread = null; // must be set after state changed to done
}
} finally {
runningThread = null;
}
}