Skip to content

Commit

Permalink
Aggregator completion thread needs to be daemon (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsgrieve committed May 1, 2023
1 parent e502037 commit 92b07d9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
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

0 comments on commit 92b07d9

Please sign in to comment.