ForkJoinPool of JDK21 : Despite having an idle worker, thesubmitted task did not run
徐佳
75317544 at qq.com
Thu Oct 23 12:52:24 UTC 2025
thanks for your response.
did you run the code by debug?
The probability of this happening is very small,We need to use debug to reproduce it , and step by step as I mentioned in my previous email.
After careful consideration, I no longer believe that this is a bug. The author should have designed it this way, as the probability of this happening is very small and recoverable。
Thanks,
Jia Xu
徐佳
75317544 at qq.com
原始邮件
发件人:Viktor Klang <viktor.klang at oracle.com>
发件时间:2025年10月23日 18:27
收件人:Joe Darcy <joe.darcy at oracle.com>, 徐佳 <75317544 at qq.com>, core-libs-dev <core-libs-dev at openjdk.org>
主题:Re: ForkJoinPool of JDK21 : Despite having an idle worker, thesubmitted task did not run
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:
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
徐佳
75317544 at qq.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20251023/111029db/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: F8FE61C2 at 8FD16500.0825FA6800000000.jpg
Type: image/jpeg
Size: 155320 bytes
Desc: not available
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20251023/111029db/F8FE61C28FD16500.0825FA6800000000-0001.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ForkJoinPoolTest.java
Type: application/octet-stream
Size: 1711 bytes
Desc: not available
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20251023/111029db/ForkJoinPoolTest-0001.java>
More information about the core-libs-dev
mailing list