Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid retaining references after successful cancelation #140

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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