SlideShare a Scribd company logo
Heap & Thread Dump
In this session
• What is Thread/Heap dump?
• When to generate ?
• How to generate ?
• Best Practices and JVM Options
• Ref and suggestion links to understand more this topic
What is Thread dump?
• A Thread Dump is a snapshot taken at a given time which provides you with
a complete listing of all created Java Threads.
• Like:
• Servlet Request
• Job (scheduler) etc.
• Each Thread found gives you information such as:
• Thread name: Name of the Thread we/vendor can specify thread name at a time
of the creating. E.g: we can configure quartz-scheduler thread or by default quartz
scheduler name looks like “instanceName+ ‘_QuartzSchedulerThread’ ”
• Thread type & priority ex: daemon prio=3 where daemon meaning their Threads
are running in background
• Java Thread ID ex: tid=0x000001111a51a811 ** This is the Java Thread Id
obtained via java.lang.Thread.getId() and usually implemented as an auto-
incrementing long 1..n**
• Java Thread State and detail ex: waiting for monitor entry [0xfffffffea5afb000]
java.lang.Thread.State: BLOCKED (on object monitor)
• And lot more…
What is Heap dump?
• A heapdump is a snapshot of JVM memory. it shows the live objects on the
heap along with references between objects. It is used to determine memory
usage patterns and memory leak suspects.
• Java Heap can be categorized into three generations: -
• Young
• Tenured
• Permanent.
• Young generation has Eden Space and two survivor spaces. All newly created
objects are kept in Eden Space and moved to one of the survivor space after it
survives few gc’s. From one survivor space it moves to another. At an instant one
of the survivor space is completely free. From the survivor space, objects are
moved to the tenured generations. Permanent holds class data, such as describing
classes and methods
• What is a Memory Leak Memory leak.
When objects are not removed from the heap even when they are not required to be
present in the heap. This can be due to application code, application server code,
database driver or third party jar files.
When to generate Thread/Heap Dump ?
• Very frequent FULL GC
• Lesser memory is reclaimed on each Full GC
• Available free heap keeps on decreasing over time
• Response time decreases
Troubleshoot
• Gather GC Information by adding the following JVM flags
-Xloggc=filename -XX:+PrintGCTimeStamps -XX:+PrintGCDetails XX:-HeapDumpOnOutOfMemoryError
How to generate Thread/Heap Dump?
• Generate Thread Dump
• By using jstack
•Ex: jstack {pid} > stack-trace.log
(Ref: http://docs.oracle.com/javase/7/docs/technotes/tools/share/jstack.html#options)
• By using jvisualvm
•After connecting to the java process one can find Threads tab ->
Thread Dump button
• Generate Heap Dump
• By using Jmap
•Ex: jmap -dump:format=b,file=<file name>.hprof <process id>
(Ref: http://docs.oracle.com/javase/7/docs/technotes/tools/share/jmap.html)
• By using Visualvm
•After connecting to the java process One can see Monitor tab->Heap
Dump button
• By adding JVM parameter
• -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$CATALINA_BASE/logs
Best Practices and JVM Options
• Keep a watch on heap usage and use alert mechanisms.
• Keep a watch on production logs
• Free up unnecessary objects.
• Close all connections in the finally block
• Don’t keep too much data in session.
• Exception handling
Type Option
Operation mode -sever
Entire heap size Specify the same value for -Xms and -Xmx.
New area size
-XX:NewRatio: value of 2 to 4
-XX:NewSize=? –XX:MaxNewSize=?. Also good to specify NewSize instead of NewRatio.
Perm size
-XX:PermSize=256 m -XX:MaxPermSize=256 m. Specify the value to an extent not to cause any trouble in the operation because it
does not affect the performance.
GC log
-Xloggc:$CATALINA_BASE/logs/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps. Leaving a GC log does not
particularly affect the performance of Java applications. You are recommended to leave a GC log as much as possible.
GC algorithm
-XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+UseConcMarkSweepGC-
XX:CMSInitiatingOccupancyFraction=75.This is only a generally recommendable configuration. Other choices could be better
depending on the characteristics of the application.
Creating a heap
dump when an
OOM error occurs
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$CATALINA_BASE/logs
Actions after an
OOM occurs
-XX:OnOutOfMemoryError=$CATALINA_HOME/bin/stop.sh or -
XX:OnOutOfMemoryError=$CATALINA_HOME/bin/restart.sh. After leaving a heap dump, take a proper operation according
to a management policy.
Ref and suggestion links to understand
more this topic
•http://www.cubrid.org/blog/dev-platform/understanding-java-garbage-collection/ - To understand garbage
collection
•http://www.cubrid.org/blog/dev-platform/how-to-monitor-java-garbage-collection/ - To Monitor Garbage
Collection
•https://blog.codecentric.de/en/2011/08/create-and-understand-java-heapdumps-act-4/
•http://www.cubrid.org/blog/dev-platform/the-principles-of-java-application-performance-tuning/
•http://javabook.compuware.com/content/memory/how-garbage-collection-works.aspx
MemoryAndThreadExample.zip
Find attached zip project, I have added MemoryLeak and Deadlock example.
That we will analysed using jvisualVM
Suggestion
and
Question / Answer
Thank You!!!

More Related Content

PDF
Thread Dump Analysis
PDF
Java Heap Dump Analysis Primer
PDF
Java troubleshooting thread dump
PDF
Tomcat and apache httpd training
PDF
Optimizing Hive Queries
PDF
Introduction to java (revised)
PDF
Java Performance Analysis on Linux with Flame Graphs
PPTX
Spring boot Introduction
Thread Dump Analysis
Java Heap Dump Analysis Primer
Java troubleshooting thread dump
Tomcat and apache httpd training
Optimizing Hive Queries
Introduction to java (revised)
Java Performance Analysis on Linux with Flame Graphs
Spring boot Introduction

What's hot (20)

PDF
Spring Boot & Actuators
PDF
Native Java with GraalVM
PPTX
Dynamic components using SPA concepts in AEM
PPT
Hibernate
PPTX
Introduction to java
PPTX
Introduction to Spring Boot
PDF
[234]멀티테넌트 하둡 클러스터 운영 경험기
PDF
Java exception handling ppt
PPTX
02 terraform core concepts
PDF
Apache Spark Overview
PPTX
Hibernate ppt
PPTX
Apache Tez - A New Chapter in Hadoop Data Processing
PDF
Performance Tuning RocksDB for Kafka Streams’ State Stores
PPT
WebLogic Scripting Tool Overview
PPT
Spring Core
PDF
RNUG - HCL Notes 11.0.1 FP2 — Performance Boost Re-Reloaded
PDF
Spark shuffle introduction
PPSX
Spring - Part 1 - IoC, Di and Beans
PDF
Secrets of Performance Tuning Java on Kubernetes
PPTX
Manage Add-On Services with Apache Ambari
Spring Boot & Actuators
Native Java with GraalVM
Dynamic components using SPA concepts in AEM
Hibernate
Introduction to java
Introduction to Spring Boot
[234]멀티테넌트 하둡 클러스터 운영 경험기
Java exception handling ppt
02 terraform core concepts
Apache Spark Overview
Hibernate ppt
Apache Tez - A New Chapter in Hadoop Data Processing
Performance Tuning RocksDB for Kafka Streams’ State Stores
WebLogic Scripting Tool Overview
Spring Core
RNUG - HCL Notes 11.0.1 FP2 — Performance Boost Re-Reloaded
Spark shuffle introduction
Spring - Part 1 - IoC, Di and Beans
Secrets of Performance Tuning Java on Kubernetes
Manage Add-On Services with Apache Ambari
Ad

Similar to Heap & thread dump (20)

PDF
Solr Troubleshooting - TreeMap approach
PDF
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
PPTX
Java 어플리케이션 성능튜닝 Part1
PDF
Introduction of Java GC Tuning and Java Java Mission Control
PPTX
Benchmarking Solr Performance at Scale
PDF
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
PDF
It's always sunny with OpenJ9
PDF
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
PDF
java-monitoring-troubleshooting
PPTX
Java performance tuning
PPTX
Considerations when deploying Java on Kubernetes
PPT
jvm goes to big data
PPTX
Hadoop cluster performance profiler
PDF
Profiler Guided Java Performance Tuning
PDF
Container Performance Analysis Brendan Gregg, Netflix
PDF
Container Performance Analysis
PPTX
Terraform Modules and Continuous Deployment
PPTX
introduction to node.js
PDF
[BGOUG] Java GC - Friend or Foe
PDF
Tomcatx troubleshooting-production
Solr Troubleshooting - TreeMap approach
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
Java 어플리케이션 성능튜닝 Part1
Introduction of Java GC Tuning and Java Java Mission Control
Benchmarking Solr Performance at Scale
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
It's always sunny with OpenJ9
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
java-monitoring-troubleshooting
Java performance tuning
Considerations when deploying Java on Kubernetes
jvm goes to big data
Hadoop cluster performance profiler
Profiler Guided Java Performance Tuning
Container Performance Analysis Brendan Gregg, Netflix
Container Performance Analysis
Terraform Modules and Continuous Deployment
introduction to node.js
[BGOUG] Java GC - Friend or Foe
Tomcatx troubleshooting-production
Ad

Recently uploaded (20)

PDF
Digital Strategies for Manufacturing Companies
PDF
Nekopoi APK 2025 free lastest update
PPTX
ai tools demonstartion for schools and inter college
PDF
top salesforce developer skills in 2025.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
System and Network Administration Chapter 2
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Introduction to Artificial Intelligence
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
AI in Product Development-omnex systems
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Digital Strategies for Manufacturing Companies
Nekopoi APK 2025 free lastest update
ai tools demonstartion for schools and inter college
top salesforce developer skills in 2025.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
Design an Analysis of Algorithms I-SECS-1021-03
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
System and Network Administration Chapter 2
Odoo POS Development Services by CandidRoot Solutions
Wondershare Filmora 15 Crack With Activation Key [2025
Introduction to Artificial Intelligence
CHAPTER 2 - PM Management and IT Context
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
AI in Product Development-omnex systems
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx

Heap & thread dump

  • 2. In this session • What is Thread/Heap dump? • When to generate ? • How to generate ? • Best Practices and JVM Options • Ref and suggestion links to understand more this topic
  • 3. What is Thread dump? • A Thread Dump is a snapshot taken at a given time which provides you with a complete listing of all created Java Threads. • Like: • Servlet Request • Job (scheduler) etc. • Each Thread found gives you information such as:
  • 4. • Thread name: Name of the Thread we/vendor can specify thread name at a time of the creating. E.g: we can configure quartz-scheduler thread or by default quartz scheduler name looks like “instanceName+ ‘_QuartzSchedulerThread’ ” • Thread type & priority ex: daemon prio=3 where daemon meaning their Threads are running in background • Java Thread ID ex: tid=0x000001111a51a811 ** This is the Java Thread Id obtained via java.lang.Thread.getId() and usually implemented as an auto- incrementing long 1..n** • Java Thread State and detail ex: waiting for monitor entry [0xfffffffea5afb000] java.lang.Thread.State: BLOCKED (on object monitor) • And lot more…
  • 5. What is Heap dump? • A heapdump is a snapshot of JVM memory. it shows the live objects on the heap along with references between objects. It is used to determine memory usage patterns and memory leak suspects. • Java Heap can be categorized into three generations: - • Young • Tenured • Permanent.
  • 6. • Young generation has Eden Space and two survivor spaces. All newly created objects are kept in Eden Space and moved to one of the survivor space after it survives few gc’s. From one survivor space it moves to another. At an instant one of the survivor space is completely free. From the survivor space, objects are moved to the tenured generations. Permanent holds class data, such as describing classes and methods • What is a Memory Leak Memory leak. When objects are not removed from the heap even when they are not required to be present in the heap. This can be due to application code, application server code, database driver or third party jar files.
  • 7. When to generate Thread/Heap Dump ? • Very frequent FULL GC • Lesser memory is reclaimed on each Full GC • Available free heap keeps on decreasing over time • Response time decreases Troubleshoot • Gather GC Information by adding the following JVM flags -Xloggc=filename -XX:+PrintGCTimeStamps -XX:+PrintGCDetails XX:-HeapDumpOnOutOfMemoryError
  • 8. How to generate Thread/Heap Dump? • Generate Thread Dump • By using jstack •Ex: jstack {pid} > stack-trace.log (Ref: http://docs.oracle.com/javase/7/docs/technotes/tools/share/jstack.html#options) • By using jvisualvm •After connecting to the java process one can find Threads tab -> Thread Dump button
  • 9. • Generate Heap Dump • By using Jmap •Ex: jmap -dump:format=b,file=<file name>.hprof <process id> (Ref: http://docs.oracle.com/javase/7/docs/technotes/tools/share/jmap.html) • By using Visualvm •After connecting to the java process One can see Monitor tab->Heap Dump button • By adding JVM parameter • -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$CATALINA_BASE/logs
  • 10. Best Practices and JVM Options • Keep a watch on heap usage and use alert mechanisms. • Keep a watch on production logs • Free up unnecessary objects. • Close all connections in the finally block • Don’t keep too much data in session. • Exception handling
  • 11. Type Option Operation mode -sever Entire heap size Specify the same value for -Xms and -Xmx. New area size -XX:NewRatio: value of 2 to 4 -XX:NewSize=? –XX:MaxNewSize=?. Also good to specify NewSize instead of NewRatio. Perm size -XX:PermSize=256 m -XX:MaxPermSize=256 m. Specify the value to an extent not to cause any trouble in the operation because it does not affect the performance. GC log -Xloggc:$CATALINA_BASE/logs/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps. Leaving a GC log does not particularly affect the performance of Java applications. You are recommended to leave a GC log as much as possible. GC algorithm -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+UseConcMarkSweepGC- XX:CMSInitiatingOccupancyFraction=75.This is only a generally recommendable configuration. Other choices could be better depending on the characteristics of the application. Creating a heap dump when an OOM error occurs -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$CATALINA_BASE/logs Actions after an OOM occurs -XX:OnOutOfMemoryError=$CATALINA_HOME/bin/stop.sh or - XX:OnOutOfMemoryError=$CATALINA_HOME/bin/restart.sh. After leaving a heap dump, take a proper operation according to a management policy.
  • 12. Ref and suggestion links to understand more this topic •http://www.cubrid.org/blog/dev-platform/understanding-java-garbage-collection/ - To understand garbage collection •http://www.cubrid.org/blog/dev-platform/how-to-monitor-java-garbage-collection/ - To Monitor Garbage Collection •https://blog.codecentric.de/en/2011/08/create-and-understand-java-heapdumps-act-4/ •http://www.cubrid.org/blog/dev-platform/the-principles-of-java-application-performance-tuning/ •http://javabook.compuware.com/content/memory/how-garbage-collection-works.aspx
  • 13. MemoryAndThreadExample.zip Find attached zip project, I have added MemoryLeak and Deadlock example. That we will analysed using jvisualVM