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

Joseph D. Darcy joe.darcy at oracle.com
Wed Oct 22 23:02:23 UTC 2025


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.
>
> 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 
> inawaitWork 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
>
> //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
>
> <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>

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


More information about the core-libs-dev mailing list