jstack
Last updated
Was this helpful?
Last updated
Was this helpful?
jstack
is a JDK utility used to generate thread dumps of a Java process. A thread dump contains a snapshot of all the threads running in the Java Virtual Machine (JVM) at a given time. It is useful for diagnosing issues like deadlocks, high CPU usage, thread contention, or long-running threads.
Identifying thread contention and deadlocks.
Debugging threads stuck in infinite loops or blocking states.
Understanding CPU-bound threads or hung processes.
Open the terminal and use the jps
command to list all Java processes:
Output example:
Start the Java Application (here it is sample-print-service maven springboot application)
jps
command output is below
Here, 83322
is the PID of our Springboot app.
Run the jstack
command with the PID to generate a thread dump:
This saves the thread dump to a file named thread-dump.txt
in the current directory.
Open the thread-dump.txt
file and look for:
BLOCKED
or WAITING
states indicating thread contention.
Deadlock information, which is explicitly mentioned if detected.
Long-running threads consuming resources.