Monday, 6 January 2014

Generating java thread dump in Linux or Unix

If your server got hang, before restarting your server you can take the thread dump of the server for identifying the issue.
In Linux or Unix machine you can identify the running processes by below command
ps -ef
By this command you will get list of all the processes running. From those list, to filter the processes list which are of java processes use the below command
ps -ef | grep java
Identify the required process which you want to kill and provide the corresponding process in below command
Kill -3 java-process Id
This command will kill the corresponding process and generates the thread dump at the server location
If you want to get the thread dump without killing the process, below command generates the thread dump at provided location
jstack java-process Id > jstack.out