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., RUNNABLEWAITINGBLOCKED, etc.) and the stack trace for each thread. Thread dumps are crucial for diagnosing performance issuesdeadlocksthread 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 behaviour

To 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


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

Popular posts from this blog

Interview question for File and FTP Adapter

What is boot.properties file and how to create

SSL Exceptions in Admin Server and Node Manager.