Skip to main content

Posts

Showing posts from March, 2025

How to Capture and Analyze a Thread Dump

We’ll explore how to  capture a thread dump  and analyze it effectively in this post. This is a continuation of  Java Dumps Uncovered: When to Use Thread Dump, Heap Dump, or Core Dump . Quick Summary A  thread dump  helps determine if a thread is stuck. However, taking a single thread dump isn’t enough—we need  at least two or more dumps  to confirm whether a thread remains in the same state over time. Ways to Capture a Thread Dump There are multiple ways to take a thread dump. We’ll explore each method using a  sample Java program  that creates two threads—one terminating in  30 seconds  and another in  5 minutes . The Java file is available in  this gist . To capture a thread dump, the first step is to  identify the Java process ID (PID) . This can be done using: $ jps or $ ps aux | grep java This command lists all running Java processes. Select the  PID  of the process for which you need the thread dump. ...

Java Dumps Uncovered: When to Use Thread Dump, Heap Dump, or Core Dump

Choosing the Right Dump for the Right Problem: Knowing which dump to use in a given situation provides a significant advantage while debugging. In this blog, we’ll explore the differences between Thread Dump, Heap Dump, and Core Dump , how to capture them, and when to use them effectively. Understanding Java Threads and Memory: When a simple Java class with a main method runs, it creates a single thread named "main" , which executes the program. In many cases, this single thread is sufficient. However, for applications handling multiple tasks simultaneously, multiple threads are necessary. For example, a web server like Tomcat would be ineffective if it handled all requests using a single thread. Instead, it creates multiple threads to manage concurrent requests. Alongside threads, Java runtime also requires memory to execute programs, which includes components like the Method Area, Heap, Stack, etc. When to Take a Thread Dump? Imagine running a Tomcat server , and a...