JVM tool guide · jvm clijstack: Capture Thread Dumps for Hang & Deadlock Analysis
jstack prints the Java stack traces of all threads in a running JVM. It is the essential tool for hang and deadlock investigations: when a service stops responding, a thread dump shows exactly where every thread is blocked, waiting on a lock, or spinning.
The modern equivalent via jcmd is Thread.print; whichever you use, the investigation technique — take two or three dumps a few seconds apart and diff them — is what matters most.
Official jstack project
Dump all threads
Print the stack of every thread. Redirect to a file for repeated dumps you can diff.
# Full dump to stdout
jstack <pid>
# With lock info, to a file
jstack -l <pid> > threads-$(date +%s).txt
# Same thing via jcmd
jcmd <pid> Thread.print -l
Detect deadlocks
jstack automatically scans for cyclic lock waits and reports the implicated threads in its output.
jstack <pid> | grep -A 10 -i 'deadlock'
Recommended hang-investigation cadence
Take dumps a few seconds apart. If the same threads are stuck in the same frames across dumps, it is almost certainly a hang, not a transient wait.
for i in 1 2 3; do
jstack <pid> > threads-$i.txt
sleep 5
done
diff <(cut -c1-120 threads-1.txt) <(cut -c1-120 threads-2.txt)
What a hung thread looks like
Look for threads in RUNNABLE spinning in the same method, or WAITING/blocked on a monitor that is never released. HEAD of the stack is where the thread is now; the 'at' frames below show the call path.
Quick startGet productive in minutes
Investigate a hang in 30 seconds
Two dumps + a diff.
jstack <pid> > t1.txt
sleep 5
jstack <pid> > t2.txt
diff t1.txt t2.txt
Last updated August 2026 · JVM Tools is independent and not affiliated with Oracle.