Deadlock, livelock and diagnostics question 144 of 180 mid
Which JDK tools do you use for concurrency problems?
- Print statements
- Correct: jcmd and jstack for dumps, JFR in production, async-profiler for lock contention
- A debugger, stepping through each thread
- VisualVM only
The toolbox worth naming:
- jcmd / jstack: thread dumps;
jcmd Thread.dump_to_file -format=jsonfor virtual threads. - JFR:
jcmd JFR.start settings=profile. Events for monitor contention (jdk.JavaMonitorEnter), park duration, thread starts and virtual thread pinning, with low enough overhead for production. - async-profiler:
-e lockfor lock contention and wall-clock mode, which is the one that shows where threads wait rather than where they burn CPU. - jcstress: for memory model questions, where an ordinary test cannot reproduce the effect at all.
- Thread MXBean:
findDeadlockedThreads()programmatically, for a health check endpoint.
A debugger is the tool that least often helps, because stopping at a breakpoint changes the interleaving you are trying to observe.
Quiz yourself on Deadlock, livelock and diagnostics Suggest a correction