Thread Dump Generation

The generation of Thread Dump can be done through various methods especially on Windows server. Following are the steps to generate the thread dump on Unix, Linux and Windows machine.

On Unix Server:

Step 1: Before generating the thread dump you must know the Java process ID running on the server. The Java processID (PID) can get using “jps” command in Unix server.  In the below screenshot, 54351 is a processID (PID) of NMSDaemon java thread.

JPS command
Figure 01: ‘jps’ command

If you want to view the details of the process then run “jps -v” command.

jps -v Command
Figure 02: ‘jps -v’ command

Step 2: Once you get the PID (e.g. 54351), you can view thread dump using “jstack <PID>” command.

Thread Dump generation using 'jstack' command
Figure 03: Thread Dump generation using ‘jstack’ command

If you want to extract the thread dump in a file then use “jstack -l <PID> > <file path and name>

Extracting the thread dump in a file
Figure 04: Extracting the thread dump in a file
Thread Dump file
Figure 05: Thread Dump file

Note: The ‘jstack’ tool is included in JDK since Java 5. If you are running in an older version of java, then run “kill -3 <PID>” command. When this command is used thread dump is sent to the standard error stream. If you are running the application in tomcat, thread dump will be sent into <TOMCAT_HOME>/logs/catalina.out file.

On Linux Server:

Step 1: Use “ps -ef | grep java” to get java process ID.
Step 2: Use “kill -SIGQUIT” command along with PID.

On Windows Server:

Step 1: Download javadump.exe
Step 2: Start the JVM with these three arguments (they must be in the right order):
-XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=C:\temp\jvmoutput.log

Step 3. Press Ctrl+Shift+Esc to open the Task Manager
Step 4. Get the PID of the Java process (under “Details” tab)
Step 5. From the command line, run “javadump.exe <pid>” command 
Step 6. The thread dump will appear in the jvmoutput.log file mentioned in step 2.

Another method to generate and analyse the thread dump on Windows server is:

Step 1: Go to the bin folder of JDK (e.g. C:\Program Files\Java\jdk1.8.0_131\bin)
Step 2: Launch JVisualVM by clicking “jvisualvm.exe”

'jvisualvm' location
Figure 06: ‘jvisualvm’ location

Step 3: Java VisualVM tool will be launched

Java Visual VM - Home Page
Figure 07: Java Visual VM – Home Page

Step 4: Right-click on the java process appears under ‘Local’

Java Visual VM - Thread Dump Generation
Figure 08: Java Visual VM – Thread Dump Generation

Step 5: Click “Thread Dump”. The thread dump will be generated and open in the right pane for analysis.

Thread Dump on Java VisualVM
Figure 09: Thread Dump on Java VisualVM

You may be interested:


Leave a Reply

Your email address will not be published. Required fields are marked *