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

Aggregator completion thread needs to be daemon #291

Merged
merged 1 commit into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.microsoft.gctoolkit.event.jvm.JVMTermination;

import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;

Expand Down Expand Up @@ -117,13 +118,22 @@ public void onCompletion(Runnable task) {
this.completionTask = task;
}

private static final ExecutorService executorService =
Executors.newSingleThreadExecutor(runnable -> {
// Use a daemon thread for executing the completion task; otherwise, the JVM will not exit.
Thread thread = new Thread(runnable, "aggregator-completion");
thread.setDaemon(true);
return thread;
}
);

/**
* Call a callback when aggregation is completed.
*/
private void complete() {
if (completionTask != null)
Executors.newSingleThreadExecutor().execute(completionTask);

if (completionTask != null) {
executorService.execute(completionTask);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ public void start(Promise<Void> promise) {
}
}

@Override
public void stop(Promise promise) {
promise.complete();
}

@Override
public boolean equals(Object other) {
// we want Object.equals(other) because it's ok to have more than 1 AggregatorEngine on the bus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ public void start(Promise<Void> promise) {
}).completionHandler(result -> {promise.complete();});
}

@Override
public void stop(Promise promise) {
promise.complete();
}

@Override
public boolean equals(Object other) {
// we want Object.equals(other) because it's ok to have more than 1 AggregatorEngine on the bus
Expand Down