Wednesday, May 30, 2018

Taking thread dumps from a java process

In this post, I would quickly like to document the easiest ways to take thread dumps from a java process

1.) Use the utility provided by the underlying JDK

on JDK 7 , use the jstack utility.

jstack <pid>

The pid can be found out by any method including grepping the ps output like:

ps -ef | grep java

or

jps.

2.) On JRockit , another utility called jrcmd is provided which is very similar to jstack .

a.) First find the pid of the running JRockit JVM

jrcmd -P

b.) Use the <pid> to print threads.

jrcmd <pid> print_threads.

3.) On JDK 8 , use jcmd

a.) Find the pid.

jcmd

b.) jcmd <pid> Thread.print

Combining these with standard unix redirection or wounding these up in a shell script that executes a thread dump every n seconds and takes multiple thread dumps would be the easiest way to capture information from your system.




No comments:

Post a Comment