From d56087240d9ca6ea126da4f281d48bf3759b40a1 Mon Sep 17 00:00:00 2001 From: Mike Jensen Date: Mon, 10 Mar 2014 12:43:22 -0600 Subject: [PATCH] Changes so that we only set the running thread if we actually ARE the running thread --- .../java/util/concurrent/FutureTask.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) 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; } }