diff --git a/classpath/java/util/concurrent/FutureTask.java b/classpath/java/util/concurrent/FutureTask.java index b8b351f614..2fb4d10e15 100644 --- a/classpath/java/util/concurrent/FutureTask.java +++ b/classpath/java/util/concurrent/FutureTask.java @@ -34,21 +34,17 @@ public class FutureTask implements RunnableFuture { @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; } }