Java – Thread’s stack trace dump

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.

  1. Start your application/ web server. I used Tomcat.
  2. Create deadlock situation.
  3. Goto Task Manager and find the process id of your java.exe or javaw.exe
  4. Goto to bin directory of JDK1.6 and execute below command:
    jstack 3516 >dump.log 2>&1
    Here assume 3516 is your process id.
  5. 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

Advertisements

2 Responses to Java – Thread’s stack trace dump

  1. PhiLho says:

    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).

  2. Kulanin says:

    Радиодетали в г.Ростове-на-Дону http://andromaril.ucoz.ru +79185540950 Владимир

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: