What is a Thread dump in unix/linux and windows:
A thread dump is a snapshot of all threads currently active in a Java Virtual Machine (JVM), showing their state and stack traces. It's invaluable for diagnosing performance issues, deadlocks, and bottlenecks.
It shows the current state (e.g., RUNNABLE, WAITING, BLOCKED, etc.) and the stack trace for each thread. Thread dumps are crucial for diagnosing performance issues, deadlocks, thread contention, or application hangs.
๐งต Why Take a Thread Dump?
To analyze CPU spikes or hangs.
To identify deadlocks or blocked threads.
To investigate thread pool behaviourTo troubleshoot memory and performance issues.
๐ How to Take a Thread Dump
Using kill -3
command:
Sends a SIGQUIT signal to the JVM process.Output goes to the standard output (
stdout
) or log file (e.g., catalina.out
for Tomcat).Using Process Explorer (GUI method):
Right-click Java process → Create Dump → Create Thread Dump
Right-click Java process → Create Dump → Create Thread Dump
Using tools like:
VisualVM – GUI-based tool to capture thread dumps.
JConsole – Available with the JDK.
Containerized Environments (Docker/Kubernetes):
kubectl exec <pod-name> -- jstack 1 > thread_dump.txt.
Java Mission Control (JMC) – Advanced profiling and diagnostics.
Analysis TipsDeadlock Detection: Look for "deadlock" or "BLOCKED" states
Thread Leaks: Compare multiple dumps for increasing thread counts
Hot Methods: Identify methods appearing frequently in stack traces
IO Wait: Look for "TIMED_WAITING (on object monitor)" with socket operations.
Comments
Post a Comment