Friday 6 May 2016

How to obtain heap dump and Thread dump in JBoss?


When your application server is hung for whatever reason, which may involve recycling your application server, you must act swiftly to collect as much diagnostics information as possible before you do that. Obtaining Java Heap dump and Thread dump are extremely valuable in such cases. Here is how you obtain these dumps for a JBoss Application server.

1. Thread dump

Thread dump shows the snapshot of all threads and their stack traces. This means you clearly see what the Application Server was working on when you took the thread dump.

Note: Always take at least 4 thread dumps at 30 seconds interval. This is to identify if a particular thread is at the same work in all thread dumps, which will mean that thread is hung up for some reason – maybe it is waiting for a backend resource to respond.

You can use the ‘jstack‘ command that comes with the JDK to obtain Java thread dump.

a. Log on to Application server

b. Identify the process id of your application server(Execute a ps command to find the process id (ps –ef |grep server_name))

Syntax: /usr/java/default/bin/jstack -l pid >> dump.log

[jboss@middlewaretech ~]$ /usr/java/default/bin/jstack -l 5365 >> /home/jboss/Desktop/threaddump.log

[jboss@middlewaretech ~]$ ls -ltr /home/jboss/Desktop/threaddump.log
-rw-r--r-- 1 jboss dba 57108 May  6 15:58 /home/jboss/Desktop/threaddump.log


The process id in the above command is 5365. The thread dump gets stored in /home/jboss/Desktop/threaddump.log

2.  Heap dump:

Java heap dump has the snapshot of the Java heap at the time of the dump. It is extremely valuable in troubleshooting ‘OutOfMemory’ errors. For example, if the biggest object in the Heap generally points to the leak suspect. When you provide the object name to the Application Developer, you give him a good starting point on analyzing the issue from his perspective.

You can use the ‘jmap’ command that comes with the JDK  to obtain the heap dump.

a. Log on to Application server

b. Identify the process id of your application server(Execute a ps command to find the process id (ps –ef |grep server_name))

Sytax: /usr/java/default/bin/jmap -dump:format=b,file=/path/to/the/dump.hprof pid


[jboss@middlewaretech ~]$ /usr/java/default/bin/jmap -dump:format=b,file=/home/jboss/Desktop/heapdump.hprof 5365

Dumping heap to /home/jboss/Desktop/heapdump.hprof ...
Heap dump file created


Here 
Format=b  à  b menace binary format
file= <path>/<name of heapdump file>  à Enter the obsolete path of file and name wherever you want to generate the file.

And finally  EAP process id and enter.
Then heap dump file will be generated in the specified path.


you can easily create a heap dump automatically when JBoss is going OutOfMemory. Just add the following Java arguments in your EAP JVM settings

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/heap.dump


Click below links for configuration of  OutOfMemory (OOM) parameters in JBOSS 6


I hope this information is helpful to you......

 Please register to this blog ...to get alerts when I post new articles or if you have need help in Middleware tasks 

1 comment:

surya said...

very detailed article. Thanks for your efforts in putting so much information.Java Thread Dump Analyzer,fastThread ,a universal tool that will parse and analyze thread dumps written in any language that runs on the JVM. It will convert your Java, Scala, Jython, JRuby thread dumps to useful information for root cause analysis (RCA).