List All Virtual Threads in a JVM
Alan Bateman
alan.bateman at oracle.com
Wed Oct 23 12:45:52 UTC 2024
On 23/10/2024 12:15, Nathan Reynolds wrote:
> How do I list all the virtual threads in a JVM?
> |ThreadMXBean.dumpAllThreads()|, |ThreadMXBean.getAllThreadIds()|,
> |ThreadGroup.enumerate()|, and |Thread.getAllStackTraces()| do not
> return virtual threads. See my question at
> https://stackoverflow.com/questions/79110874/list-the-virtual-threads-in-java
> <https://stackoverflow.com/questions/79110874/list-the-virtual-threads-in-java>.
>
> 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.
>
Right, the cited APIs were all re-specified in JDK 19 to only enumerate
platform threads. This extends to JVMTI APIs and the debugger wire
protocol too. None of these APIs scale, e.g. ThreadMXBean requires a
mapping of thread identifier to Thread for local use, getting a snapshot
of all virtual Thread objects in the heap would require a stop-the-world
and/or walking the heap.
There are lots of ideas for expanding the serviceability APIs in this
area. Some of these will require significant changes to the debugger
protocol and agent. In the mean-time, the only serviceability that
include all threads are the heap dump and the thread dump taken with
jcmd Thread.dump_to_file.
-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20241023/7fbe3914/attachment.htm>
More information about the loom-dev
mailing list