Showing posts with label stack dump. Show all posts
Showing posts with label stack dump. Show all posts

Thursday, December 26, 2013

JStack - Generating stack dump


This would be useful to analyze a root cause, when an application has suddenly stopped working or not responding . There could be a some kind of deadlock or waiting processes or something else. 
JStack would help in getting the stack dump to a currently running java process.

JStack comes along with JDK kit, need not to install separately.

Go to command prompt, type below command with java process id.

>jstack <pid>

To identify the java process id, you can 'jps' command.

>jps  => this will list out the all java process id's.
Output:
5730 main  => this is my java process id.
10800 jps
8732

To get more details about which process ID belongs to which process use below command
> jps -ml

To get the additional information about the locks.
>jps  -l  <pid>

Jstack can also be used to get the thread dump for remotely running processes.
>jps  <remote host name/ip address>

To write stack dump to a file:
>jstack -l 7840 >  D:\Test\kklog.txt

">" is important to write into a file.


Some useful resources on this.
http://www.ibm.com/developerworks/library/j-5things8/
http://docs.oracle.com/javase/7/docs/technotes/tools/share/jstack.html