<div dir="ltr"><div dir="ltr"><div dir="ltr">In my opinion you should not treat VirtualThread differently than any other class, for example ArrayList. Like ArrayList, JVM may have hundreds of thousands of VirtualThread's and in every second thousands can be created and thousands can be garbage collected.<br>In my opinion you cannot expect that JVM will give you all virtual threads. (Compared to platform threads, platform thread count is usually limited to hundreds). Like for ArrayList, you can take heap dump<br><br>Anyway, JVM keeps all virtual threads in jdk.internal.vm.ThreadContainers.RootContainer.TrackingRootContainer#VTHREADS. But I hope it is dead end and will be abandoned</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">śr., 23 paź 2024 o 13:47 Nathan Reynolds <<a href="mailto:numeralnathan@gmail.com" target="_blank">numeralnathan@gmail.com</a>> napisał(a):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>How do I list all the virtual threads in a JVM? <code>ThreadMXBean.dumpAllThreads()</code>, <code>ThreadMXBean.getAllThreadIds()</code>, <code>ThreadGroup.enumerate()</code>, and <code>Thread.getAllStackTraces()</code> do not return virtual threads.  See my question at <a id="m_4303093374312352285m_-5485975714896601122gmail-LPlnk648813" rel="noopener noreferrer" href="https://stackoverflow.com/questions/79110874/list-the-virtual-threads-in-java" target="_blank">https://stackoverflow.com/questions/79110874/list-the-virtual-threads-in-java</a>.</div><div><br></div><div>I can see how these APIs would not scale for virtual threads.  What are the thoughts for an API to list all the virtual threads?  
For an in-process API, would an API that returns Stream<Thread> scale?  I am not sure how an MXBean API can stream Threads to make it scale.<br></div><div><br></div><br></div>
</blockquote></div>