Java Concurrency Interview

Virtual threads and structured concurrency question 120 of 180 senior

How do you debug a system running a million virtual threads?

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.

virtual-threads diagnostics

Quiz yourself on Virtual threads and structured concurrency Suggest a correction