Trying to understand internals of Java virtual threads

Pedro Lamarão pedro.lamarao at prodist.com.br
Fri Sep 1 16:36:16 UTC 2023


Em sex., 1 de set. de 2023 às 13:08, Siddharth Jain <siddhsql at gmail.com>
escreveu:


> I just have a simple question re: java virtual threads which is how does
> the virtual thread know when its time to yield to another thread? as
> example say i am running code using the synchronous pg JDBC driver inside a
> vthread. there is nothing in the pg JDBC driver per se that tells a vthread
> to yield when its waiting for response back from the database. in fact the
> driver is not even aware of any vthread. is the yield logic something
> managed at the JVM layer? how? any details would be appreciated. thanks,
>

This is generally the same for virtual threads in the JVM and platform
threads in the operating system.
Threads don`t block or unblock themselves; the system blocks and unblocks
threads as appropriate.
When a platform thread calls into the system for I/O, it is the I/O
subsystem that causes the thread to block (waiting for I/O) and to unblock
(when I/O has completed).

-- 
Pedro Lamarão
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20230901/63289cf4/attachment-0001.htm>


More information about the loom-dev mailing list