package demo; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.locks.LockSupport; public class ForkJoinPoolTest { /* * java -version * java version "21.0.8" 2025-07-15 LTS * Java(TM) SE Runtime Environment (build 21.0.8+12-LTS-250) * Java HotSpot(TM) 64-Bit Server VM (build 21.0.8+12-LTS-250, mixed mode, sharing) */ public static void main(String[] args) throws InterruptedException { //Add a breakpoint on the 1864th line of ForkJoinPool source code in awaitWork method. ForkJoinPool pool = new ForkJoinPool(2);//total 2 Threads //create worker w1, keep running and printing pool information pool.submit(() -> { while(true) { System.err.println("==================="); System.err.println("QueuedSubmissionCount:" + pool.getQueuedSubmissionCount()); System.err.println("ActiveThreadCount:" + pool.getActiveThreadCount()); System.err.println("PoolSize:" + pool.getPoolSize()); System.err.println("==================="); LockSupport.parkNanos(5 * 1000_000_000L);//5s } }); //create another worker w2 pool.submit(() -> System.out.println(Thread.currentThread().getName() + " : finished task1")); System.out.println("submited task1"); Thread.sleep(3 * 1000);// waiting for task1 to end //now task1 finished and no task in queue, w2 is pausing at breakpoint in awaitWork method. pool.submit(() -> System.out.println(Thread.currentThread().getName() + " : finished task2")); System.out.println("submited task2"); //after submitted task2, resume w2 , and then w2 will park on line 1891 ,although there is still task2 in the Submission queue Thread.sleep(5 * 60 * 1000); pool.close(); } }