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,10 +34,8 @@ public class FutureTask<T> implements RunnableFuture<T> {
@Override @Override
public void run() { 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)) { if (currentState.compareAndSet(State.New, State.Running)) {
runningThread = Thread.currentThread();
try { try {
result = callable.call(); result = callable.call();
} catch (Throwable t) { } catch (Throwable t) {
@ -45,11 +43,9 @@ public class FutureTask<T> implements RunnableFuture<T> {
} finally { } finally {
currentState.compareAndSet(State.Running, State.Done); currentState.compareAndSet(State.Running, State.Done);
handleDone(); handleDone();
runningThread = null; // must be set after state changed to done
} }
} }
} finally {
runningThread = null;
}
} }
private void handleDone() { private void handleDone() {