Java Thread dump in Linux(Unix)

Java thread dump is a stack traces of all active threads in a Java Application. Which gives the information or state of all Java Threads which are live/active in a running Application of Java and their states.

The following are the steps for collecting Java thread dumps in Linux(Unix)

Find the process id of the Java application for which you want to collect thread dump, by using any of the following commands

jps This is a inbuilt tool which comes with Java(JDK tools) useful to find the process id's of the java application

ps -eaf | grep java

"This 'ps' command comes with Unix or Linux itself"

Java Thread Dump

Using kill -QUIT or kill -3 as shown below.

Java Thread Dump using kill

kill -QUIT or kill -3 will produce the following output of stdout console of Java

Output of Java thread dump after kill -quit

Using Java in built tools

1) jstack

2) jcmd

3) jconsole

4) jmc

5) jvisualvmk

jconsole,jmc and jvisualvm are the UI based tools. Taking java thread dumps is a difficult tasks to use UI tools while we are using Unix or Linux boxes

In this article, lets use the jstack to collect thread dumps fron Linux or Unix

Java Thread Dump using jstack

Output of jstack will be printed in the terminal which we used, we can direct the output of jstack to any file by using the redirect command

jstack java_application.pid >> thread dumps.txt