ForkJoinPool of JDK21 : Despite having an idle worker, the submitted task did not run

Viktor Klang viktor.klang at oracle.com
Thu Oct 23 10:27:19 UTC 2025


Also, this doesn't reproduce for me.

/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home/bin/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)


/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home/bin/java ~/Desktop/ForkJoinPoolTest.java
===================
submited task1
QueuedSubmissionCount:1
ActiveThreadCount:2
PoolSize:2
===================
ForkJoinPool-1-worker-2 : finished task1
submited task2
ForkJoinPool-1-worker-2 : finished task2
===================
QueuedSubmissionCount:0
ActiveThreadCount:1
PoolSize:2
===================
===================
QueuedSubmissionCount:0
ActiveThreadCount:1
PoolSize:2
===================
^C%


Cheers,
√


Viktor Klang
Software Architect, Java Platform Group
Oracle
________________________________
From: core-libs-dev <core-libs-dev-retn at openjdk.org> on behalf of Joseph D. Darcy <joe.darcy at oracle.com>
Sent: Thursday, 23 October 2025 01:02
To: 徐佳 <75317544 at qq.com>; core-libs-dev <core-libs-dev at openjdk.org>
Subject: Re: ForkJoinPool of JDK21 : Despite having an idle worker, the submitted task did not run

Jia Xu, this mailing list is not a forum to submit bugs.

>From https://openjdk.org/guide/#jbs---jdk-bug-system, if you don't have a JBS account, you can submit bugs at https://bugreport.java.com/bugreport/

Regards,

-Joe

On 10/22/2025 3:45 PM, 徐佳 wrote:
Hi,

Despite having an idle worker, the submitted task did not run.




Steps to reproduce:

-------------------

1. before all , add a breakpoint on the 1864th line of ForkJoinPool source code in awaitWork method.

2. then debug the following code,and a thread will be paused at breakpoint

3. after "submited task2" printed in the console, resume the breakpoint.

4. Despite having an idle worker, task2 did not run.




public class ForkJoinPoolTest {

        public static void main(String[] args) throws InterruptedException {

                //Add a breakpoint on the 1864th line of ForkJoinPool source code in awaitWork method.

        <
 span class="Apple-tab-span" style="white-space: pre;">

                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.getActiv
 eThreadCount());

                                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() + " : fin
 ished 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



                //if no new task submitted, task2 will not run.

                Thread.sleep(5 * 60 * 1000);

                pool.close();

        }




}




result:


[cid:part1.I3Epj5MD.0kOu5Ijt at oracle.com]


Environment:
------------


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)




it seams that a task submitted between method “scan”and “awaitWork” may not be executed immediately

I think the reason is that the worker did not recheck the waiting condition "hasTasks" between "enqueue" and "park"

I don't know whether this is a bug or it's just designed this way


Please let me know if more information is needed.

Thanks,
Jia Xu

________________________________
<https://wx.mail.qq.com/home/index?t=readmail_businesscard_midpage&nocheck=true&name=%E5%BE%90%E4%BD%B3&icon=https%3A%2F%2Fthirdqq.qlogo.cn%2Fg%3Fb%3Doidb%26k%3DITa58KjAzQ2Sy661ARGMag%26s%3D0&mail=75317544%40qq.com&code=ovqAUzHwnHYC7-bg8gt5zIWB5w7lrIw4naNXXN4i8PT0cdk69vq9G4d0D9uz44QQxBxJAXH7CqfvaQpIQtyFFA>
[https://thirdqq.qlogo.cn/g?b=oidb&k=ITa58KjAzQ2Sy661ARGMag&s=0]
徐佳
75317544 at qq.com


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20251023/94071ed3/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 5E110CCA at B2062160.7A5EF968.jpg
Type: image/jpeg
Size: 155320 bytes
Desc: 5E110CCA at B2062160.7A5EF968.jpg
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20251023/94071ed3/5E110CCAB2062160.7A5EF968-0001.jpg>


More information about the core-libs-dev mailing list