Java – Thread’s stack trace dump
March 22, 2009 2 Comments
Recently I was dealing with a deadlock issue. Usually I use eclipse break points to create deadlock situation at the same time find the line/code which causes the deadlock. But this one is bit complex scenario where it is not easy to have break points move line by line to reproduce the deadlock.
I realized it will be easy if I know the stack trace of the deadlocked threads. Gone through the Thread API and found Thread.dumpStack() method. But the dumpStack() method was a real dump that it shows the stack trace of the call to dumpStack() method instead of actual thread’s state dump.
While googling I came across JStack tool in JDK1.6 which helped me to get the thread dump easily.
Steps to capture the thread dump.
- Start your application/ web server. I used Tomcat.
- Create deadlock situation.
- Goto Task Manager and find the process id of your java.exe or javaw.exe
- Goto to bin directory of JDK1.6 and execute below command:
jstack 3516 >dump.log 2>&1
Here assume 3516 is your process id. - After the above command you can open dump.log to see the various threads’ stack trace.
Reference: http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jstack.html
You can even avoid a step and use jps tool to get the IDs of the Java processes (and only them). The -v option make it more verbose if you need help to distinguish the various processes (same runs with different parameters for example).
Радиодетали в г.Ростове-на-Дону http://andromaril.ucoz.ru +79185540950 Владимир