how to get thread and heap dump
Hi Techrunnr Readers, this document deals with how to get thread and heap dump.
A heap dump is a snapshot of the memory of a Java™ process. The snapshot contains information about the Java objects and classes in the heap at the moment the snapshot is triggered. Because there are different formats for persisting this data, there might be some differences in the information provided.
A thread dump is a snapshot of the state of all threads that are part of the process. The state of each thread is presented with a so-called stack trace, which shows the contents of a thread’s stack. Some of the threads belong to the Java application you are running, while others are JVM internal threads
Basically, thread and heap dumps are used for analyzing running java process, for improving the performance. This provides the full details about all the calls and status of those calls.
Here is a small shell script to get thread and heap dump of a process.
Create shell script file,
add the following lines to created file.
Make the script executable
chmod +x threadHeap.sh
Execute the script
[ubuntu@localhost ~]$ sh threadHeap.sh
Thread and Heap Dump Script
Warning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQ
user1 20751 0.9 3.1 7959308 1027172 ? Sl Jul19 154:39 /usr/java/jdk1.7.0_79/bin/java -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1g -Xmx3g -Xss256k -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+DisableExplicitGC -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=7171 –
Which Java Process ID you need to take heapDump and threaddump
You selected the following Pid
Dumping heap to /tmp/heapdump-0012018-07-30-03.hprof …
Heap dump file created
Heap Dump and heap dumo got sucessfull. Check the file in /tmp/heapdump-0012018-07-30-03.hprof & /tmp/threaddump-239-2018-07-30-03.log
Now you have taken thread dump and Heap Dump in /tmp location
© 2018, Techrunnr. All rights reserved.