Skip to content

Commit

Permalink
Avoid retaining references after successful cancelation
Browse files Browse the repository at this point in the history
Fixes #139
  • Loading branch information
dmlloyd committed Feb 13, 2024
1 parent 56ebd23 commit 93c7f80
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions src/main/java/org/jboss/threads/EnhancedQueueExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2609,6 +2609,7 @@ public boolean cancel(final boolean mayInterruptIfRunning) {
case ASF_ST_SUBMITTED: {
this.state = ASF_ST_CANCELLED;
notifyAll();
doCancel();
return true;
}
case ASF_ST_RUNNING: {
Expand All @@ -2627,6 +2628,9 @@ public boolean cancel(final boolean mayInterruptIfRunning) {
}
}

void doCancel() {
}

public V get() throws InterruptedException, ExecutionException {
int state;
synchronized (this) {
Expand Down Expand Up @@ -2864,33 +2868,49 @@ static int wrongType() throws ClassCastException {
}

final class RunnableScheduledFuture extends AbstractScheduledFuture<Void> {
final Runnable runnable;
Runnable runnable;

RunnableScheduledFuture(final Runnable runnable, final long delay, final TimeUnit unit) {
super(delay, unit);
this.runnable = runnable;
}

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<V> extends AbstractScheduledFuture<V> {
final Callable<V> callable;
Callable<V> callable;

CallableScheduledFuture(final Callable<V> callable, final long delay, final TimeUnit unit) {
super(delay, unit);
this.callable = callable;
}

V performTask() throws Exception {
return callable.call();
try {
return callable.call();
} finally {
callable = null;
}
}

void doCancel() {
callable = null;
}

StringBuilder toString(final StringBuilder b) {
Expand Down Expand Up @@ -2940,7 +2960,7 @@ StringBuilder toString(final StringBuilder b) {
}

final class FixedRateRunnableScheduledFuture extends RepeatingScheduledFuture<Void> {
final Runnable runnable;
Runnable runnable;

FixedRateRunnableScheduledFuture(final Runnable runnable, final long delay, final long period, final TimeUnit unit) {
super(delay, period, unit);
Expand All @@ -2957,13 +2977,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<Void> {
final Runnable runnable;
Runnable runnable;

FixedDelayRunnableScheduledFuture(final Runnable runnable, final long delay, final long period, final TimeUnit unit) {
super(delay, period, unit);
Expand All @@ -2979,6 +3003,10 @@ Void performTask() {
return null;
}

void doCancel() {
runnable = null;
}

StringBuilder toString(final StringBuilder b) {
return super.toString(b).append(runnable);
}
Expand Down

0 comments on commit 93c7f80

Please sign in to comment.