Question On Project Loom
Alan Bateman
Alan.Bateman at oracle.com
Tue Apr 27 08:12:54 UTC 2021
On 27/04/2021 04:47, Sohail Khan wrote:
> :
>
> I am trying to summarize my queries in a single email. I am using the
> Mailing List for the very first time, and not sure about the mailing
> convention, therefore please correct me if I am wrong.
>
> 1. Alan, going by the example you shared of Blocking Queue trying to
> fetch an element and getting blocked. This implies all Java API
> that can block, have been modified to Detect Virtual Threads
> being used, and then save the context and park it for later
> execution. Is my understanding correct? The push operation will
> place elements and mark blocked virtual threads as Ready.
>
Yes, all blocking operations have to be re-examined. The example I used
with a BlockingQueue is just one many that park in j.u.concurrent. The
Blocking Operations [1] wiki page gives a (not too stale) status of what
some of the blocking APIs when invoked in the context a virtual thread.
> 1. Ron, Whenever we make API calls that currently use blocking IO
> Like Plain old blocking sockets, the API has been modified to
> detect a virtual thread being used, they internally switch to the
> usage of non blocking NIO apis transparently. Is my understanding
> correct? Also when the request comes from Classic threads, the
> implementation will be using the blocking apis, similar to what's
> happening today.
>
That's correct. Arthur pointed to the old socket implementation
PlainSocketImpl using blocking syscalls. That implementation has not
been used (by default) since JDK 12 and the plan is to remove that code
soon.
>
> 1. Will JNI calls only be allowed from Classic threads and not
> virtual threads, because JNI could allow some one execute blocking
> code from within a virtual thread.
>
Virtual threads can use JNI but it will pin the thread if it blocks in
the native method or calls back into Java with a native frame on the stack.
There are several recorded talks linked from the wiki page that might be
useful for your explorations.
-Alan
[1] https://wiki.openjdk.java.net/display/loom/Blocking+Operations
More information about the loom-dev
mailing list