What is the difference between Heap dump and Thread dump in Java?
Answer
A heap dump is a snapshot of all objects in the JVM heap at a given moment — it captures what is in memory (object types, sizes, references, and object count). It is used to diagnose memory leaks and excessive memory usage. Generate with: jmap -dump, VisualVM, or configure the JVM with -XX:+HeapDumpOnOutOfMemoryError. Analyze with Eclipse MAT or VisualVM. A thread dump is a snapshot of all threads' current states — it shows what each thread is doing, what locks it holds, and what it is waiting for. It is used to diagnose deadlocks, thread starvation, and CPU bottlenecks. Generate with jstack, kill -3, or VisualVM. Look for BLOCKED threads and circular lock dependencies in deadlock analysis.
Previous
What is the var keyword in Java?
Next
What are the main garbage collection algorithms in Java?