jstack - print Java thread stack traces for a running Java process
jstack [-l] [-e] pid
Options you will use
-l- Long listing: locked ownable synchronizers (java.util.concurrent locks).
-e- Extended thread information.
-m- Mixed mode (Java and native frames). Removed from jstack in JDK 9: use jhsdb jstack --mixed.
Examples
$ sudo -u appuser jstack -l 1210 > dump1.txtSame content as jcmd 1210 Thread.print -l.
$ grep -A1 'java.lang.Thread.State' dump1.txt | sort | uniq -c | sort -rnCluster threads by state and top frame.
Gotchas
- Take three dumps about ten seconds apart: threads that are identical in all three are stuck; threads that move are merely busy.
- A deadlock is reported explicitly at the end: "Found one Java-level deadlock:".
Try jstack in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.