Java – Thread’s stack trace dump
March 22, 2009 1 Comment
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.