A Thread Dump helps you track the exact activity of every running thread in your Java application at a specific point in time. It is essential for diagnosing high CPU usage, hanging tasks, and deadlocks.
How to Generate a Thread Dump
Method 1: Using the Command Line (Recommended)
You don't need keyboard shortcuts. Use the built-in JDK tool jcmd:
- Find the Java process ID:
- jps -l
- 2. Print the thread dump to a file:
- jcmd <PID> Thread.print > threaddump.txt
Method 2: Keyboard Shortcut (Console Window Only)
If you run the application directly inside an interactive command terminal:
Windows: Press
Ctrl + Break(orCtrl + Fn + Bon modern laptops).Linux / Mac: Press
Ctrl + \(or runkill -3 <PID>).
Simple Test Program
Run this program in your terminal, then trigger a thread dump using either method above to view the active thread stack traces:
Program :- LoopTest.java
public class LoopTest {
public static void main(String[] args) throws InterruptedException {
while (true) {
System.out.println("Running...");
Thread.sleep(1000); // Prevents console spamming
}
}
}