While JBoss Enterprise Application Platform makes managing our Java applications more effective, there are still some troubleshooting tactics for Java applications that we should be aware of. Our applications can be memory-intensive, and in instances of poor performance, we’ll often need to take and analyze a Java heap dump to discover the root cause of our memory issues.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Create Heap Dump
Find the process ID for Java:
pgrep java
Create a heap dump:
sudo jcmd PID GC.heap_dump -all=true heapcheck.hprof
Check that the heap dump has been created in
/opt/jboss-eap
:cd /opt/jboss-eap ls
- Configure Automatic Heap Dump Creation
Create a directory to store heap dumps and move the
heapcheck.hpof
file to it:sudo mkdir /opt/jboss-eap/heapdumps sudo mv heapcheck.hprof /opt/jboss-eap/heapdumps/
Configure JBoss to automatically generate a heap dump when there is an out of memory error; ensure it is saved to the newly-created directory:
export JAVA_OPTS="-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/jboss-eap/heapdumps/oomdump.hprof"
Restart JBoss:
sudo systemctl restart jboss-eap-rhel
- Parse the Heap Dump
Download the Eclipse Memory Analyzer:
cd curl -O http://mirror.math.princeton.edu/pub/eclipse/mat/1.9.1/rcp/MemoryAnalyzer-1.9.1.20190826-linux.gtk.x86_64.zip
Extract the contents of the download:
unzip MemoryAnalyzer-1.9.1.20190826-linux.gtk.x86_64.zip
Run the script to parse the heap dump:
cd mat sudo ./ParseHeapDump.sh /opt/jboss-eap/
Confirm the heap dump has been parsed:
ls /opt/jboss-eap/heapdumps/