Dumping is a well-known term in performance testing, whether it is heap dump or thread dump both are very useful to carry out the root cause analysis. We have already discussed Heap Dump and its analysis in the previous post. Now, let’s move further and try to understand what is the thread dump and how it can be analysed.
Similar to Heap Dump, Thread Dump is a snapshot of the status of all the threads at a particular time. Thread dumps are vital artefacts to diagnose CPU spikes, deadlocks, poor response times, memory problems, unresponsive applications and other system problems. Thread Dump helps to find out what every thread in the JVM is doing at a particular point in time. Are some threads stuck in a deadlock? Are all the threads running? Which threads are waiting for the blocked resources etc? All these questions can be answered by analysing the thread dump.
Before jumping on to the main topic, firstly I would like to introduce you to some basic terms which are helpful to understand the concept:
A thread is a series of statements which can be processed in parallel in the same program to achieve concurrency. All the Java threads are managed by JVM (Java Virtual Machine) which is mapped with an operating system thread, also called a Native Thread. Threads help to allow multiple activities within a single process and act like lightweight processes. Each thread has a unique identifier, name, and category. Some of the basic features of a Thread are:
- A thread is lightweight and faster than a process
- Threads share the same address space and therefore can share both data and code
- Context switching between threads is usually less expensive than between processes
- The cost of thread intercommunication is relatively low than that of process intercommunication
- Threads allow different tasks to be performed concurrently
Java is a multi-threaded application that allows multiple-thread execution at any particular time. A web server uses tens to hundreds of threads to process a large number of concurrent users and achieve multithreading. But the problem occurs when two or more threads utilize the same resources and leads deadlock situation.
A deadlock is a situation when two or more threads are waiting for the other threads to complete their tasks in order to complete their own tasks. To identify the root cause of the deadlock, a threads dump is required.
Example: Let’s consider a scenario in which thread A holds a resource X and needs resource Y which is blocked by thread B. At the same time thread B needs resource X which is blocked by thread A. Hence a deadlock is created and no progress is made within a program.
4. Thread Dump:
Re-iterating the definition again. Thread Dump is a snapshot of the status of all the threads at a particular time. It helps to find out what every thread in the JVM is doing at a particular point in time. Are some threads stuck in a deadlock? Are all the threads running? Which threads are waiting for the blocked resources etc? All these questions can be answered by analysing the thread dump.
In the next post, we will discuss the life cycle of a thread.
You may be interested:
- Life Cycle of Thread
- Thread Dump Generation
- How to read Thread Dump?
- Thread Dump Analysis
- fastThread – Thread Dump Analyzer