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 @Override
public void run() { public void run() {
// must set running thread before we change the state for cancel to work if (currentState.compareAndSet(State.New, State.Running)) {
runningThread = Thread.currentThread(); runningThread = Thread.currentThread();
try { try {
if (currentState.compareAndSet(State.New, State.Running)) { result = callable.call();
try { } catch (Throwable t) {
result = callable.call(); failure = t;
} catch (Throwable t) { } finally {
failure = t; currentState.compareAndSet(State.Running, State.Done);
} finally { handleDone();
currentState.compareAndSet(State.Running, State.Done); runningThread = null; // must be set after state changed to done
handleDone();
}
} }
} finally {
runningThread = null;
} }
} }