<p dir="ltr">By the way, deadlocks specifically should be discoverable automatically without a thread dump.</p>
<br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 20 Nov 2024, 07:10 Dr Heinz M. Kabutz, <<a href="mailto:heinz@javaspecialists.eu">heinz@javaspecialists.eu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">With platform threads, we have had good techniques for finding threading <br>
issues. For example, a thread dump would reveal deadlocks, livelocks and <br>
contention.<br>
<br>
However, with virtual threads, most of these techniques won't work <br>
anymore. For example, here is a SimpleDeadlock:<br>
<br>
import java.util.concurrent.locks.*;<br>
<br>
public class SimpleDeadlock {<br>
     public static void main(String... args) throws InterruptedException {<br>
         var monitor1 = new Object();<br>
         var monitor2 = new Object();<br>
         Thread.startVirtualThread(() -> {<br>
             synchronized (monitor1) {<br>
                 LockSupport.parkNanos(10_000_000);<br>
                 synchronized (monitor2) {<br>
                     System.out.println("Got both locks");<br>
                 }<br>
             }<br>
         });<br>
         Thread.startVirtualThread(() -> {<br>
             synchronized (monitor2) {<br>
                 LockSupport.parkNanos(10_000_000);<br>
                 synchronized (monitor1) {<br>
                     System.out.println("Got both locks");<br>
                 }<br>
             }<br>
         }).join();<br>
     }<br>
}<br>
<br>
If we run this with Java 21-23 and -Djdk.trackAllThreads=false, the <br>
carrier thread indicate that they are carrying some virtual threads, but <br>
these do not appear in the full dump. In Java 24+24, the virtual threads <br>
are parked instead of pinned, and thus they vanish completely from the <br>
thread dumps.<br>
<br>
Is there any project or workgroup where debugging of virtual threads is <br>
being looked at?<br>
<br>
Regards<br>
<br>
Heinz<br>
-- <br>
Dr Heinz M. Kabutz (PhD CompSci)<br>
Author of "The Java™ Specialists' Newsletter" - <a href="http://www.javaspecialists.eu" rel="noreferrer noreferrer" target="_blank">www.javaspecialists.eu</a><br>
Java Champion - <a href="http://www.javachampions.org" rel="noreferrer noreferrer" target="_blank">www.javachampions.org</a><br>
JavaOne Rock Star Speaker<br>
Tel: +30 69 75 595 262<br>
Skype: kabutz<br>
<br>
</blockquote></div>