Now that jstack is installed, you are ready to troubleshoot. Here is a quick guide on how to capture a thread dump. 1. Find the Java Process ID (PID)
. While the Java Runtime Environment (JRE) allows you to run Java applications,
This installs the latest stable version of OpenJDK and includes jstack . jstack -version Use code with caution.
After installation, you may need to add the JDK's bin directory to your system's PATH so you can run jstack from any directory. install jstack on ubuntu
Note: The -headless variant is ideal for production servers as it excludes GUI libraries, saving disk space. Step 4: Verify the Installation
If after these steps you still get a "command not found" error, double-check your PATH variable with echo $PATH and ensure the JDK's bin directory is included. Also, verify that the jstack file actually exists in the JDK's bin directory by listing its contents ( ls $JAVA_HOME/bin/ ).
jstack -l <PID> > full_thread_dump.txt
Always update your local package index before installing new software to ensure you fetch the latest versions: sudo apt update Use code with caution. Step 3: Install the Java Development Kit (JDK)
If a specific Java thread is causing high CPU usage, you might want to look at the threads in thread-dump format.
Method 2: Install Specific OpenJDK Version (Recommended for Production) Now that jstack is installed, you are ready to troubleshoot
For more detailed information including lock information, use the -l flag:
Pass the PID to jstack to output the real-time thread dump to your terminal: jstack Use code with caution. 3. Save the Thread Dump to a File For deep analysis, redirect the output to a text file: jstack > thread_dump.txt Use code with caution. Troubleshooting Common Errors 1. "jstack: command not found" You installed the JRE instead of the JDK.