Stop Parsing Raw Stack Traces: Debugging Virtual Thread Deadlocks with JDK 26 JSON Thread Dumps
If you are still running jstack or grepping through a 500MB plain-text thread dump to debug a virtual thread deadlock, you are wasting valuable time. With millions of concurrent virtual threads now standard in modern high-throughput Java applications, traditional text-based thread dumps have become an unreadable, unparseable wall of text.
Heads up: if you want to see these patterns applied to real interview problems, javalld.com has full machine coding solutions with traces.
Why Most Developers Get This Wrong
- Grepping raw text: Treating virtual threads like legacy platform threads and expecting standard regex to parse millions of concurrent stack traces without crashing your terminal.
-
Ignoring carrier thread mapping: Failing to map the underlying carrier thread (
ForkJoinPool-1-worker-*) to the mounted virtual thread, leading to ghost deadlock diagnoses. - Manual pinning detection: Relying on developers to manually spot synchronized block pinning instead of programmatically querying the thread's mounting state.
The Right Way
Leverage JDK 26's native JSON thread dump output coupled with structured query tools to instantly isolate deadlocks and carrier thread pinning at scale.
-
Generate structured dumps: Trigger JSON-formatted dumps via
jcmd <pid> Thread.dump_to_file -format=json <file>. -
Query with jq: Parse the machine-readable output to filter for
blockedOnobjects, thread states, and carrier mappings. - Automate pinning checks: Programmatically scan the JSON for virtual threads stuck in transition states on carrier threads.
Show Me The Code (or Example)
Run this single-line jq command to extract only the deadlocked virtual threads along with their associated carrier threads from a JDK 26 JSON thread dump:
jq '.threads[] | select(.isVirtual == true and .state == "BLOCKED") | {
virtualThreadId: .tid,
name: .name,
blockedOnObject: .blockedOn.object,
blockedByThread: .blockedOn.ownerThreadId,
carrierThread: .carrierThread // "none"
}' thread_dump.json
Key Takeaways
-
Ditch jstack:
jstackis legacy;jcmdwith-format=jsonis the standard for modern observability pipelines. - Automate diagnostics: Build automated alerts in your CI/CD or APM using structured JSON parsing rather than brittle regex.
- Watch the carrier: Always correlate the virtual thread's state with its carrier thread to diagnose performance degradation from pinning.
Top comments (0)