Terminal outputs can disappear quickly. Save the thread dump to a file for offline analysis or to share with your team: jstack > /tmp/thread_dump.txt Use code with caution. Troubleshooting Common Errors Error: "ptrace: Operation not permitted"
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).
The -l flag adds lock information and will explicitly report found deadlocks at the end. install jstack on ubuntu
Pass the PID to jstack to output the current thread states to your terminal screen: jstack Use code with caution. 3. Save the Dump to a File
Scroll to the very bottom of the file and append the following lines (adjust the directory name if your JDK version is different): Terminal outputs can disappear quickly
To take a thread dump of a running Java process, find the and run: jstack > threaddump.txt Use code with caution. Copied to clipboard
Before installing anything, check if your system already has jstack available. Open your terminal and run: jstack -version Use code with caution. It is used to print Java stack traces
Thread dumps can be thousands of lines long. It is best practice to export the data to a text file for analysis: jstack > thread_dump.txt Use code with caution. Troubleshooting Common Errors Error: "Unable to open socket file" or "Permission denied"
# Alternative using jcmd (JDK 7+) jcmd <PID> Thread.print > thread_dump.txt
The basic syntax of jstack is: