Skip to content

Commit

Permalink
Common pool cannot be shut down.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed Nov 1, 2024
1 parent 182ea3d commit 21935fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
package nl.vpro.util;

import lombok.extern.log4j.Log4j2;
import org.junit.platform.launcher.TestExecutionListener;
import org.junit.platform.launcher.TestPlan;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;

import org.junit.platform.launcher.TestExecutionListener;
import org.junit.platform.launcher.TestPlan;

/**
* A junit TestExecutionListener that just makes sure that all ThreadPools are shutdown after the tests.
* Also, it calls {@link ForkJoinPool#awaitQuiescence(long, TimeUnit)} (100s) on {@link ForkJoinPool#commonPool()}
*/
@Log4j2
public class ThreadPoolShutdowner implements TestExecutionListener {

@Override
public void testPlanExecutionFinished(TestPlan testPlan) {

ThreadPools.shutdown();
log.info("Shutting down ForkJoinPool.commonPool() too");
ForkJoinPool.commonPool().shutdown();
log.info("Waiting for ForkJoinPool.commonPool() too");
// commonPool cannot be shut down. But you can wait for tasks
boolean b = ForkJoinPool.commonPool().awaitQuiescence(100, TimeUnit.SECONDS);

}

}
5 changes: 2 additions & 3 deletions vpro-shared-util/src/main/java/nl/vpro/util/ThreadPools.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,12 @@ public Thread newThread(@NonNull Runnable r) {
false,
Thread.NORM_PRIORITY));


public static void shutdown() {
public static void shutdown() {
log.info("Shutting down thread pools");
copyExecutor.shutdown();
startUpExecutor.shutdown();
backgroundExecutor.shutdown();
longBackgroundExecutor.shutdown();
}
}
}

0 comments on commit 21935fb

Please sign in to comment.