Wednesday, February 13, 2019

How to capture thread dump

Option 1:
Since JDK 5, jstack tool is shipped in JDK_HOME/bin folder.

jstack -l  <pid> > <file-path>

sudo -u tomcat jstack -l 12345 > /var/tmp/thedump.log
sudo -u tomcat /usr/java/jdk1.8.0_181/bin/jstack -J-d64 -l 12308 >>/var/tmp/thedump.log

Option 2:
Since JDK 7, The jcmd tool was introduced for troubleshooting issues with JVM applications. It has various capabilities such as identifying java process Ids, capturing heap dumps, capturing thread dumps, acquiring garbage collection statistics, etc.

jcmd <pid> Thread.print > <file-path>

jcmd 12345 Thread.print > /var/tmp/thedump.log

Option 3:
If only JREs are installed on production machines, you can use "kill -3" option to capture thread dump.

kill -3 <pid>

The thread dump is sent to the standard error stream. If you are running your application in tomcat, thread dump will be sent into <TOMCAT_HOME>/logs/catalina.out file.

No comments:

Post a Comment