Saturday, October 3, 2009

Getting thread dump for java application

When an java application server freezes or becomes non-responsive, it is recommended to generate a thread dump for the application. A thread dump is a user-friendly snapshot of the threads and monitors in a Java Virtual Machine (JVM). A thread dump can range from fifty lines to thousands of lines of diagnostics depending on how complex your application is.

On UNIX platforms you can send a signal to a program by using the kill command. This is the quit signal, which is handled by the JVM. On Solaris you can use the command kill -QUIT process_id, where process_id is the process id of your Java program.

run the command kill -QUIT <pid> or kill -3 <pid> on shell which will cause the thread dump to be displayed your application console. Alternatively you can enter the key sequence <CTRL> \ in the window where the Java program was started. This is why it's critical to redirect standard output & standard error to a log file so it is captured when you need a thread dump.

On Windows platform, enter the key sequence <CTRL> <break> for the thread dump of your application.

Thread States :: The key used for the thread states in Thread dump is:
R ==> Running or runnable thread
S ==> Suspended thread
CW ==>Thread waiting on a condition variable
MW ==> Thread waiting on a monitor lock
MS ==> Thread suspended waiting on a monitor lock

No comments: