Java / Java 21 Virtual Threads Interview questions
How can you detect thread pinning in a production system?
In production you generally want continuous, low-overhead visibility rather than a one-off diagnostic run, so a persistent JFR recording subscribed to the jdk.VirtualThreadPinned event is the usual approach.
Feed that event stream into your existing observability pipeline and correlate spikes in pinning frequency with increases in p99 latency or carrier-pool saturation - pinning reduces the effective number of available carriers, so its impact shows up as tail-latency degradation under load rather than obvious errors.
The -Djdk.tracePinnedThreads flag is better suited to targeted investigation in staging, since printing a stack trace per pinning event is comparatively heavier for a high-throughput production service.
More Related questions...