Friday, October 22, 2010

How to generate a threaddump for java based process

Windows
Can be captured in following ways

1) Using Ctrl-Break :
The Java application that you want to produce a thread dump for must be running / started in a command console. When you want to produce a thread dump press Ctrl-Break.

2) Using jstack :
step 1) Use jps command to find out the process id (pid) of the java process for which the thread dump is to be generated.
eg output for jps
C:\>jps
3316 Deadlock
3476 Jps
step 2) Use jstack command to along with the process id to generate the threaddump.
syntax : jstack
eg: c:/>jstack 3316

Linux or Solaris

1)Using Ctrl-\:
If the JVM is running in a console then simply press Ctrl-\.

2)Sending QUIT signal:
If the JVM is running in the background then send it the QUIT signal:

kill -QUIT process_id

There process_id is the process number of the running Java process. The thread dump will be sent to wherever standard out is redirected too.

You can generally get the process numbers of of all running Java processes with the command:

ps axf | grep java

3) Using jstack:
Steps as mentioned above in the Windows Section

No comments:

Post a Comment