• Thread dump is a text file. Is a snapshot of the performance of JVM threads. Record in stack form. It helps us analyze what’s wrong with the program. Helps quickly locate problems. Thread dump is meaningful only after analyzing the id of the thread that occupies system resources.
  • Heap dump is a binary file that can be opened and viewed with the help of the jvisualVM tool provided by Java. This file is a snapshot of the JVM heap memory. It records what classes there are at that time, the number of classes, the number and size of instances, and the content of instances. There is also some additional information, as shown in the figure below.

Use JDK tools to get the dump

Get Thread dump: jstack > filename.txt

Heap dump: jmap -dump:live,format=b,file=heap-dump. Bin

Parsing the thread dump file structure

The specific text is not shown, you can generate a thread dump for comparison.

Full Thread Dump Java HotSpot(TM) 64-bit Server VM (25.231-B11 mixed mode):Copy the code

This is the generation time of Thread dump and the JVM version information.

The first line of each method call stack has such a similarly structured string, explained in the figure above.

Thread state

deadlock

A deadlocked thread usually refers to a situation in which multiple threads occupy each other’s resources during invocation and cannot be released.

runnable

Generally, the thread is in the execution state.

blocked

The thread is blocking.

waiting on condition

The thread is waiting for resources or for a condition to occur. The specific reason needs to be analyzed in combination with stack information.

  • You may be waiting to lock a resource
  • Maybe it’s sleep
  • May be insufficient network resources, this should be combined with the use of the system information.

Waiting for monitor entry or in object.wait ()

Synchronized heavyweight locks in Java are implemented with Moniter. Moniter has two queues. One is an entry set and the other is a wait set. After synchronized upgrades to heavyweight lock, the thread that fails to compete for lock will be recorded in the entry set, and the thread state is waiting for monitor entry. When a thread that is competing for a lock calls the wait method on the lock Object, the state is recorded in object.wait ().