Analyzing thread dump for your Java application

Is your J2EE application responding slowly ? Is it getting hanged every now and then ?

The best way to start is take thread dump whenever you think performance is not to up to the mark and then analyze it.

Taking Thread Dump:

On unix system , you just have to first find out PID of your java process. You can use PS –alf | grep –in ‘java’ to find out the same.

Once you have PID, simply execute Following command:

 kill -3 PID

This will inform JVM to take current snapshot. It will be then copy to your standard log file/stdout file.

On windows, you have to execute ctr-break on the command prompt.


Analyzing Thread Dump:

If you don’t have right to tool for this, then it’s very hard to grasp what’s going on. I have used TDA http://www.ohloh.net/p/tda . This one is very nice, simple, easy and free tool. Once you open your log file (containing dump) in this tool, it will show all threads in tree structure, along with details of each thread. Most important of it is the thread state which could be like runnable, wait, wait on monitor, wait on conditions etc. Also it will show sleeping and locking threads separately. This will help you to identify the object on which threads are waiting and thereby identifying bottleneck in the system.

It has one feature to compare multiple thread dumps. It helps in finding out long running threads instantly.

If you have set -XX:+PrintClassHistogram JVM option while starting it, in thread dump it will also provide information of number of instance create for each classes along with the total bytes required for those objects. This should give you a fair idea of what classes and which modules are the one to look first for the optimization.


Rahul Ner

(RNer)

No comments: