Skip to content

Commit

Permalink
Merge pull request #140 from dmlloyd/leak-139
Browse files Browse the repository at this point in the history
Avoid retaining references after successful cancelation
  • Loading branch information
dmlloyd authored Mar 5, 2024
2 parents 4c2e5ce + 333d473 commit e405c8e
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 @@ -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: {
Expand All @@ -2632,6 +2633,9 @@ public boolean cancel(final boolean mayInterruptIfRunning) {
}
}

void doCancel() {
}

@SuppressWarnings("unchecked")
public V get() throws InterruptedException, ExecutionException {
int state;
Expand Down Expand Up @@ -2869,33 +2873,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 @@ -2945,7 +2965,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 @@ -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<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 @@ -2984,6 +3008,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 e405c8e

Please sign in to comment.