jstack is a command-line utility that comes bundled with the Java Development Kit (JDK). It is used to print Java stack traces of Java threads for a specified Java process. This tool is invaluable for developers and system administrators who need to debug applications, diagnose deadlocks, or identify performance bottlenecks (CPU spikes).
Because jstack is part of the JDK (not the JRE), you cannot simply install it as a standalone package; you must install the full Java Development Kit. install jstack on ubuntu
# For JDK 11
sudo apt install openjdk-11-jdk
Save to file
jstack <PID> > thread_dump.txt
Get PID of Java process
ps aux | grep java
# or
jps -l