Java 1.6 onwards, “jstack.exe”, a utility tool comes along with the JDK installation and can be found in the folder %JAVA_HOME%\bin. If you aren’t able to find it along with your JDK installation, even then you should be able to download this utility without any issues at all. This utility just requires the PID of the Java process that you are interested to collect the thread dump. In this article, you will be able to understand and know how to collect thread dump from Tomcat using Jstack utility tool.
Just FYI, the utility that comes along with the JDK installation isn’t complete and lacks the following features, if you are trying to figure out why these aren’t working on your Production systems.
The process of collecting thread dumps using Jstack utility tool:
- Option “–m”: This option is used to generate the thread dump in MIXED MODE, which means that you will be able to print native stack traces in addition to the Java stack.
- Option “-F”: This option is used to generate the thread dump FORCIBLY.
If you are on a UNIX based operating system then you will be able to find the PID of the java process using the following command:
ps –ef | grep java
If you are on a Windows-based operating system then you have to follow the steps below:
- Press Ctrl + Alt + Del and click on “Task Manager” button
- Click on the “Processes” tab
- From the menu, click on “View” -> “Select Columns” and check the PID (Process Identifier) check box as well
- Now you can see the PID of your “java.exe” in the “Processes” tab.
Fire a command prompt window (CMD) and traverse to %JAVA_HOME%\bin directory, and then run the following command with the PID that you’ve obtained in the above step.
Jstack –l %PID% > ThreadDump.log
Since the process is not responding, you could try generating the thread dump using –F option.
By issuing the command above– you will be able to find your thread dump on %JAVA_HOME%\bin with the name as given on the command prompt.