<story><title>Virtual Threads: New Foundations for High-Scale Java Applications</title><url>https://www.infoq.com/articles/java-virtual-threads/</url></story><parent_chain><item><author>ccooffee</author><text>This is a great writeup, and reignites my interest in Java. (I&amp;#x27;ve long considered &amp;quot;Java Concurrency in Practice&amp;quot; to be the _best_ Java book ever written.)&lt;p&gt;I haven&amp;#x27;t been able to figure out how the &amp;quot;unmount&amp;quot; of a virtual thread works. As stated in this article:&lt;p&gt;&amp;gt; Nearly all blocking points in the JDK have been adapted so that when encountering a blocking operation on a virtual thread, the virtual thread is unmounted from its carrier instead of blocking.&lt;p&gt;How would I implement this logic in my own libraries? The underlying JEP 425[0] doesn&amp;#x27;t seem to list any explicit APIs for that, but it does give other details not in the OP writeup.&lt;p&gt;[0] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;openjdk.org&amp;#x2F;jeps&amp;#x2F;425&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;openjdk.org&amp;#x2F;jeps&amp;#x2F;425&lt;/a&gt;</text></item></parent_chain><comment><author>pron</author><text>&amp;gt; How would I implement this logic in my own libraries?&lt;p&gt;There&amp;#x27;s no need to if your code is in Java. We had to change low-level I&amp;#x2F;O in the JDK because it drops down to native.&lt;p&gt;That&amp;#x27;s not to say every Java library is virtual-thread-friendly. For one, there&amp;#x27;s the issue of pinning (see the JEP) that might require small changes (right now the problem is most common in JDBC drivers, but they&amp;#x27;re already working on addressing it). The bigger issue, mostly in low-level frameworks, is implicit assumptions about a small number of shared threads, whereas virtual threads are plentiful and are never pooled, so they&amp;#x27;re never shared. An example of such an issue is in Netty, where they allocate very large &lt;i&gt;native&lt;/i&gt; buffers and cache them in ThreadLocals, which assumes that the number of threads is low, and that they&amp;#x27;re reused by lots of tasks.</text></comment>
<story><title>Virtual Threads: New Foundations for High-Scale Java Applications</title><url>https://www.infoq.com/articles/java-virtual-threads/</url></story><parent_chain><item><author>ccooffee</author><text>This is a great writeup, and reignites my interest in Java. (I&amp;#x27;ve long considered &amp;quot;Java Concurrency in Practice&amp;quot; to be the _best_ Java book ever written.)&lt;p&gt;I haven&amp;#x27;t been able to figure out how the &amp;quot;unmount&amp;quot; of a virtual thread works. As stated in this article:&lt;p&gt;&amp;gt; Nearly all blocking points in the JDK have been adapted so that when encountering a blocking operation on a virtual thread, the virtual thread is unmounted from its carrier instead of blocking.&lt;p&gt;How would I implement this logic in my own libraries? The underlying JEP 425[0] doesn&amp;#x27;t seem to list any explicit APIs for that, but it does give other details not in the OP writeup.&lt;p&gt;[0] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;openjdk.org&amp;#x2F;jeps&amp;#x2F;425&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;openjdk.org&amp;#x2F;jeps&amp;#x2F;425&lt;/a&gt;</text></item></parent_chain><comment><author>ecshafer</author><text>Java Concurrency in Practice is a fantastic book. I had DL as a professor for about a half dozen courses in undergrad, including Concurrent and Parallel Programming. Absolutely fantastic professor, with a lot of insight into how parallel programming really works at the language level. One of the best courses I&amp;#x27;ve taken.</text></comment>