Sunday, February 5, 2012

Java Thread Dump and Heap Dump

A thread dump is a dump of the stacks of all live threads. Thus useful for analyzing what an app is up to at some point in time, and if done at intervals handy in diagnosing some kinds of 'execution' problems (e.g. thread deadlock).

Obtain / Extract Thread Dump : jstack PID > outfile 
You can pass -l (small L) Long listing

How to read thread dump : Java thread dumps are just text files, so you can read them with any text editor.

Analyse java thread dumphttp://www.cubrid.org/blog/dev-platform/how-to-analyze-java-thread-dumps/

A heap dump is a dump of the state of the Java heap memory. Thus useful for analyzing what use of memory an app is making at some point in time so handy in diagnosing some memory issues, and if done at intervals handy in diagnosing memory leaks.

Obtain / Extract Heap Dumpjmap -dump:format=b,file=fileName.hprof pid

How to Read heap dump using javaVisualVM below in File -> Load -> select heap dump and select file .hprof

In java opts add option -XX:+HeapDumpOnOutOfMemoryError. If process fail in out of memory heap dump will be created.


Java VisualVM - This tool available from java 1.6 it used to visualize/monitor applications from jdk 1.4 and higher. You can use this tool to connect to remote Host as well 

In linux box You just have to put $JAVA_HOME/bin in your $PATH variable. So, you can type 
jps - Jps to see java process
jstack  - (you can get jvmid using jps)

Eclipse Memory Analyzer is also good tool to analyse memory issue with .hprof file.
a. Download .zip file
b. extract .zip file
c. open ./MemoryAnalyzer for memory analyzer tool

http://www.eclipse.org/mat/

No comments :

// Below script tag for SyntaxHighLighter