Question Regarding JEP 444: Virtual Threads and Use of ForkJoinPool

Olivier Peyrusse kineolyan at protonmail.com
Wed Jun 14 12:33:06 UTC 2023


And following on this question regarding FJP, is there any possible interaction between the virtual threads and any library externally using ForkJoinPools?

I am asking this question with this JUnit issue in mind https://github.com/junit-team/junit5/issues/3108
For example, if a test were to be executed by JUnit executor relying on the FJP, and if the test were using Virtual Threads, would we see interactions between those Virtual threads and JUnit executor, particularly through the test `thread instanceof ForkJoinWorkerThread`?

I am trying to build an example to see how the two will interact and see with my own eyes.

------- Original Message -------
Le mercredi 14 juin 2023 à 03:11, David Holmes <david.holmes at oracle.com> a écrit :


> 
> 
> On 14/06/2023 10:31 am, Bazlur Rahman wrote:
> 
> > My understanding is that the ForkJoinPool usually adopts a
> > divide-and-conquer approach, breaking a larger task into several smaller
> > subtasks. In this context, the task is essentially a virtual thread. I
> > am interested to know how the divide-and-conquer algorithm plays out
> > when the ForkJoinPool tries to break down a virtual thread into smaller
> > units.
> 
> 
> It isn't the FJP that does that, it is the use of ForkJoinTasks and the
> associated APIs by the programmer that does that.
> 
> Cheers,
> David
> -----
> 
> > Thank you,
> > -
> > A N M Bazlur Rahman
> > 
> > ---
> > /"And say: 'My Lord, increase me in knowledge.'" - Quran 20:114./
> > 
> > Java Champion
> > Software Engineer
> > JUG Leader, JUGBD.org http://JUGBD.org
> > Java Queue Editor, InfoQ
> > https://www.infoq.com/profile/A-N-M-Bazlur-Rahman/
> > Editor at Foojay.io https://foojay.io/today/author/bazlur-rahman/
> > About Me https://bazlur.ca/about/
> > https://bazlur.ca/ https://bazlur.ca/
> > 
> > On Tue, Jun 13, 2023 at 8:13 PM David Holmes <david.holmes at oracle.com
> > mailto:david.holmes at oracle.com> wrote:
> > 
> > Hi,
> > 
> > On 14/06/2023 9:50 am, Bazlur Rahman wrote:
> > > Hello,
> > >
> > > I was reading JEP 444, which discusses the implementation of Virtual
> > > Threads. I've observed that the JDK's virtual thread scheduler
> > employs a
> > > work-stealing ForkJoinPool operating in FIFO mode, which is distinct
> > > from the common pool operating in LIFO mode.
> > >
> > > This has sparked my curiosity because ForkJoinPool, to my
> > understanding,
> > > has not traditionally been designed to handle I/O-bound tasks.
> > However,
> > > the design of virtual threads seems to be aimed precisely at
> > addressing
> > > such tasks.
> > 
> > Yes and it is the virtual threads mechanism that handles the I/O-bound
> > tasks, not the underlying FJP. Where a regular thread in the FJP would
> > block on an I/O operation and become unavailable for further use, it is
> > the virtual thread that blocks, allowing the carrier thread in the FJP
> > to continue executing other virtual threads.
> > 
> > Cheers,
> > David
> > -----
> > 
> > > Therefore, I'm curious as to why Java has opted to use the
> > ForkJoinPool
> > > for scheduling virtual threads. I would greatly appreciate it if you
> > > could shed some light on what makes this design choice effective in
> > > managing I/O-bound tasks, despite the ForkJoinPool's traditional
> > usage
> > > patterns.
> > >
> > > Thank you for your time and consideration. I look forward to your
> > > insights on this subject.
> > > Thank you,
> > >
> > > -
> > > A N M Bazlur Rahman
> > >
> > > ---
> > > /"And say: 'My Lord, increase me in knowledge.'" - Quran 20:114./
> > >
> > > Java Champion
> > > Software Engineer
> > > JUG Leader, JUGBD.org
> > >
> > <https://mailtrack.io/trace/link/331a3fc3a3fa6407b1c1a71207d689d0bc35baca?url=http%3A%2F%2FJUGBD.org&userId=2428395&signature=31820ea85face89b https://mailtrack.io/trace/link/331a3fc3a3fa6407b1c1a71207d689d0bc35baca?url=http%3A%2F%2FJUGBD.org&userId=2428395&signature=31820ea85face89b>
> > > Java Queue Editor, InfoQ
> > >
> > <https://mailtrack.io/trace/link/4e67b5f2b63d9a192a80a28578b56f26ab3495b9?url=https%3A%2F%2Fwww.infoq.com%2Fprofile%2FA-N-M-Bazlur-Rahman%2F&userId=2428395&signature=0e89d13e753a8ce2 https://mailtrack.io/trace/link/4e67b5f2b63d9a192a80a28578b56f26ab3495b9?url=https%3A%2F%2Fwww.infoq.com%2Fprofile%2FA-N-M-Bazlur-Rahman%2F&userId=2428395&signature=0e89d13e753a8ce2>
> > > Editor at Foojay.io
> > >
> > <https://mailtrack.io/trace/link/ae78bc70831add10a5229ae14321984a51f052eb?url=https%3A%2F%2Ffoojay.io%2Ftoday%2Fauthor%2Fbazlur-rahman%2F&userId=2428395&signature=8a905c0967fa07c1 https://mailtrack.io/trace/link/ae78bc70831add10a5229ae14321984a51f052eb?url=https%3A%2F%2Ffoojay.io%2Ftoday%2Fauthor%2Fbazlur-rahman%2F&userId=2428395&signature=8a905c0967fa07c1>
> > > About Me
> > >
> > <https://mailtrack.io/trace/link/040f4646e384e62ba0900a14bc61657dbcec43b2?url=https%3A%2F%2Fbazlur.ca%2Fabout%2F&userId=2428395&signature=fc5823af331c641e https://mailtrack.io/trace/link/040f4646e384e62ba0900a14bc61657dbcec43b2?url=https%3A%2F%2Fbazlur.ca%2Fabout%2F&userId=2428395&signature=fc5823af331c641e>
> > > https://bazlur.ca/ https://bazlur.ca/
> > >
> > <https://mailtrack.io/trace/link/130dee54b46a76f0c11f910de05c700cdda0bb77?url=https%3A%2F%2Fbazlur.ca%2F&userId=2428395&signature=90ba6ea5871c4665 https://mailtrack.io/trace/link/130dee54b46a76f0c11f910de05c700cdda0bb77?url=https%3A%2F%2Fbazlur.ca%2F&userId=2428395&signature=90ba6ea5871c4665>


More information about the loom-dev mailing list