diff --git a/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java b/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java index 1f9b110..a3139bb 100644 --- a/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java +++ b/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java @@ -2614,6 +2614,7 @@ public boolean cancel(final boolean mayInterruptIfRunning) { case ASF_ST_SUBMITTED: { this.state = ASF_ST_CANCELLED; notifyAll(); + doCancel(); return true; } case ASF_ST_RUNNING: { @@ -2632,6 +2633,9 @@ public boolean cancel(final boolean mayInterruptIfRunning) { } } + void doCancel() { + } + @SuppressWarnings("unchecked") public V get() throws InterruptedException, ExecutionException { int state; @@ -2869,7 +2873,7 @@ static int wrongType() throws ClassCastException { } final class RunnableScheduledFuture extends AbstractScheduledFuture { - final Runnable runnable; + Runnable runnable; RunnableScheduledFuture(final Runnable runnable, final long delay, final TimeUnit unit) { super(delay, unit); @@ -2877,17 +2881,25 @@ final class RunnableScheduledFuture extends AbstractScheduledFuture { } Void performTask() { - runnable.run(); + try { + runnable.run(); + } finally { + runnable = null; + } return null; } + void doCancel() { + runnable = null; + } + StringBuilder toString(final StringBuilder b) { return super.toString(b).append(runnable); } } final class CallableScheduledFuture extends AbstractScheduledFuture { - final Callable callable; + Callable callable; CallableScheduledFuture(final Callable callable, final long delay, final TimeUnit unit) { super(delay, unit); @@ -2895,7 +2907,15 @@ final class CallableScheduledFuture extends AbstractScheduledFuture { } V performTask() throws Exception { - return callable.call(); + try { + return callable.call(); + } finally { + callable = null; + } + } + + void doCancel() { + callable = null; } StringBuilder toString(final StringBuilder b) { @@ -2945,7 +2965,7 @@ StringBuilder toString(final StringBuilder b) { } final class FixedRateRunnableScheduledFuture extends RepeatingScheduledFuture { - final Runnable runnable; + Runnable runnable; FixedRateRunnableScheduledFuture(final Runnable runnable, final long delay, final long period, final TimeUnit unit) { super(delay, period, unit); @@ -2962,13 +2982,17 @@ Void performTask() { return null; } + void doCancel() { + runnable = null; + } + StringBuilder toString(final StringBuilder b) { return super.toString(b).append(runnable); } } final class FixedDelayRunnableScheduledFuture extends RepeatingScheduledFuture { - final Runnable runnable; + Runnable runnable; FixedDelayRunnableScheduledFuture(final Runnable runnable, final long delay, final long period, final TimeUnit unit) { super(delay, period, unit); @@ -2984,6 +3008,10 @@ Void performTask() { return null; } + void doCancel() { + runnable = null; + } + StringBuilder toString(final StringBuilder b) { return super.toString(b).append(runnable); }