Virtual threads and structured concurrency question 120 of 180 senior
How do you debug a system running a million virtual threads?
jstackas usual- Correct:
jcmd Thread.dump_to_file -format=json, which dumps virtual threads grouped by their structured scope; plainjstackdoes not show them - The JVM prints them on OOM
- You cannot, that is the trade-off
jstack and the classic dump show only platform threads, so your carriers appear and the million
virtual threads on top of them do not. The replacement is
jcmd <pid> Thread.dump_to_file -format=json threads.json, which walks the virtual threads too and,
for structured concurrency, nests them by scope so the output reads as a tree of who forked whom.
Also worth naming: JFR events jdk.VirtualThreadStart, jdk.VirtualThreadEnd,
jdk.VirtualThreadPinned and jdk.VirtualThreadSubmitFailed; and the fact that a million threads
produce a dump measured in hundreds of megabytes, so grep it rather than reading it.
Quiz yourself on Virtual threads and structured concurrency Suggest a correction