Thread dumps provide a lot of valuable information about a running java process. Let’s see how to take Thread dumps of a running Java process.
Solution 1: Using kill -3
If you are running *nix system, find the process id of running java, either by using jps command or by using ps -aef | grep java. Once you get the process id, do the following (assuming process id to be 5459)
$kill -3 5459
This shall print the Thread dump on console. If the console output has been redirected to a file, the thread dump can be found there.
Solution 2: Using jstack
jstack is a utility bundled with JDK. It can be used to get thread dumps. Let’s see how to do it
Many times this command does not respond, use the flag -F to force the thread dump. More details here
Solution 3: Using VisualVM
VisualVM is a nice tool that ships with JDK. It provides a way to peek into JVM using a UI. It’s present in the JDK bin folder with name jvisualvm. Launch the VisualVM and connect to the process of which Thread dumps is to be taken.
There is a button “Thread Dump” on right hand upper side. Click the button and a thread dump shall be taken and displayed in a tab.