Thursday 16 August 2018

Java: How to analyze thread dumps?

In my previous post, I explained how to collect thread dumps. In this post, I am going to explain how to analyze thread dump using ‘TDA - Thread Dump Analyzer’.

a.   Download TDA jar file
b.   Collect the thread dumps
c.   Use tda application to analyze thread dumps.

Download TDA jar file
You can download TDA jar file from below location.




Read README.md file, it provides you information about the latest version of Thread Dump analyzer.

Collect thread dumps for a java application

HelloWorld.java
public class HelloWorld {
 public static void main(String args[]) throws Exception {
  Thread t1 = new Thread() {
   public void run() {
    while (true) {
     try {
      Thread.sleep(1000);
     } catch (Exception e) {

     }
    }
   }
  };

  t1.start();
 }
}

Compile and run HelloWorld.java application.


Open another command prompt (or) terminal and execute jcmd command.

C:\>jcmd
16656 sun.tools.jcmd.JCmd
18612
15484 HelloWorld

As you see jcmd output, HelloWorld application runs with process id 15484.

Execute the command ‘jstack -l 15484 > threadDump’.

Above command collects the thread dumps to threadDump file.

Analyze thread dump using TDA (Thread Dump Analyzer)
Execute the command ‘java -jar tda.jar’ file.

It opens below user interface.


File -> Open. Load the thread dump file.


Now you can analyse the thread dumps.

Previous                                                 Next                                                 Home

No comments:

Post a Comment