How to generate a thread dump?

3 minute readKnowledge baseArticle ID 205199280Last reviewed 2026-11-18 ()

Issue

  • How do I generate a thread dump?

  • I need to diagnose performance or execution issues, for example, thread deadlock related to server hangs.

Resolution

To diagnose performance issues, gather information about what is happening inside the Java Virtual Machine (JVM) while it is experiencing issues. A thread dump, which displays all currently running threads, is one of the tools used for this purpose.

Generate a thread dump from the UI

If Jenkins or its agents are operating normally, this is the easiest method. You need the administrator permission on the system.

  • For Jenkins, go to https://ci.example.com/threadDump.

  • For an agent named xyz, go to https://ci.example.com/computer/xyz/systemInfo.

If Jenkins does not respond in the UI, or you need complementary information, use the command-line methods in the following sections.

These are convenient for a quick live review but not useful for the automatic analysis.

Get the PID of the Java process

To generate a thread dump from the command line, you first need the process ID (PID) of the Java process where Jenkins runs. Use one of the following methods:

  • jcmd -l/jps: From a Unix terminal or Windows cmd with the JDK installed. It lists the instrumented JVMs on the target system.

  • ps -ef | grep java: From a Unix terminal only. It lists the process ID of all matching Java processes.

  • Process explorer: Use the task manager UI of your operating system, find the process, and view its PID in the corresponding column.

    • On Windows and Linux (Ubuntu), the application is named Task Manager.

    • On macOS, the application is named Activity Monitor.

Get the thread dump

After you obtain the PID ($PID), use one of the following methods to generate the thread dump:

  • jcmd: From a Unix terminal or Windows cmd with the JDK installed. Use jcmd in preference to jstack for enhanced diagnostics and reduced performance overhead. Run the command as the same user that runs Jenkins:

    sudo -u $JENKINS_USER jcmd $PID Thread.print > jenkins-threaddump.txt
    ▼
  • jstack: From a Unix terminal or Windows cmd with the JDK installed. It prints Java thread stack traces for a Java process, core file, or remote debug server. Run the command as the same user that runs Jenkins:

    sudo -u $JENKINS_USER jstack -F $PID > jenkins-threaddump.txt
    ▼
  • jconsole: From a Unix terminal or Windows cmd with the JDK installed. JConsole is a real-time graphical monitoring tool that complies with the Java Management Extensions (JMX) specification. It uses the instrumentation of the JVM to provide information about the performance and resource consumption of applications running on the Java platform.

  • kill -3 $PID: From a Unix terminal only. This command does not kill the process. It generates a thread dump, and it prints no output, which is expected. The thread dump is sent to the system error or output logs.

Generate several thread dumps while the performance issue is occurring. To collect several thread dumps automatically, along with other performance data, run the collectPerformanceData.sh script. For details, refer to What is collectPerformanceData.sh and how does it help?. Attach the output to your CloudBees support ticket so that CloudBees Support can help diagnose further.

Notes

  1. Some of these commands might require administrator permissions.

  2. These tools require a JDK, not only a JRE. Run the commands from $JDK_PATH/bin, or add $JDK_PATH/bin to your system $PATH.

  3. On Windows, if the PID is not displayed in Task Manager, select View > Select Columns, and then select PID (Process Identifier).

  4. To run Unix commands on Windows, you can install Cygwin.

  5. For supported Java versions, refer to CloudBees Jenkins Platform supported Java versions.

This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by Cloudbees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.