Java / Java 21 Virtual Threads Interview questions
How do you monitor and debug virtual threads using JFR?
Java Flight Recorder gained several events specific to virtual threads: jdk.VirtualThreadStart and jdk.VirtualThreadEnd for lifecycle tracking, jdk.VirtualThreadPinned for pinning incidents, and jdk.VirtualThreadSubmitFailed for scheduler-level failures.
Recording these over time lets you correlate spikes in pinning or submit failures with latency regressions, rather than guessing from application logs alone.
For a point-in-time snapshot, jcmd <pid> Thread.dump_to_file -format=json <file> produces an extended thread dump that groups virtual threads under the carrier they're currently mounted on, which is far more useful at scale than the traditional text thread dump, since a plain dump listing millions of virtual threads individually would be unmanageable.
More Related questions...