How to generate a thread dump

Issue

  • How do I generate a thread dump.
  • Diagnosing performance or execution issues, for instance, thread deadlock related to server hangs.

Resolution

In order to diagnose performance issues we can gather information about what is happening inside the JVM while it is experiencing issues. One of the tools used to help diagnose performance issues is a thread dump which displays all currently running threads.

If Jenkins or its slaves are operating normally, you can obtain a thread dump remotely by going to http://your.jenkins.example/threadDump. For a slave named ‘xyz’, go to http://your.jenkins.example/computer/xyz/systemInfo. You need to have the administrator permission on the system. This is by far the easiest.

Following, alternative methods are provided when Jenkins is not responding to web UI or complementary info was needed.

1. Get the PID of the Java process where Jenkins is running

To generate a thread dump the first part is to obtain the process id (or PID). There are multiple methods to obtain the PID:

  • jps - From Unix Terminal or Windows Cmd with the JDK installed into the OS. It lists the instrumented Java Virtual Machines (JVMs) on the target system.
  • ps -ef | grep java - From Unix Terminal only. It is used to obtain the process id of all java processes.
  • Process explorer - There are task manager UI applications (System Tools) which can be used to obtain the process id. Find the process and view its PID in the corresponding column.
    • On Windows and Linux (Ubuntu) is named as Task manager
    • On Mac OS is named as Activity Monitor

2. Get the thread dump

After obtaining the process id (**$PID**), the next step is to generate the thread dump. There are multiple ways to obtain the thread dump.

  • kill -3 $PID - From Unix Terminal only. It will NOT kill the process, but instead generate a thread dump. This NOT generate any output which is normal. The output of this command is sent to system err/out logs.
  • jstack $PID - From Unix Terminal or Windows Cmd with the JDK installed into the OS. It prints Java thread stack traces for a Java process, core file, or remote debug server. Sometimes if the process takes too long, then you might need to run with -F. Jstack (without -F) will only work if you run it as the same user as the jenkins java process runs as.
  • jconsole - From Unix Terminal or Windows Cmd with the JDK installed into the OS. The JConsole graphical user interface is a monitoring tool (real time) that complies to the Java Management Extensions (JMX) specification. JConsole uses the extensive instrumentation of the Java Virtual Machine (JVM) to provide information about the performance and resource consumption of applications running on the Java platform.

Note : The release of JDK 8 introduced Java Mission Control, Java Flight Recorder, and jcmd utility for diagnosing problems with JVM and Java applications. It is suggested to use the latest utility, jcmd instead of the previous jstack utility for enhanced diagnostics and reduced performance overhead.

Generating a few of these thread dumps during the performance issue would be required. Attach the output generated from these commands to a cloudbees support ticket, so we can help diagnose further.

Notes

  1. Some of these commands might require admin permissions.
  2. When JDK is required (it does not mean JRE). To run the proposed commands you need to run them from $JDK_PATH/bin or from anywhere by including $JDK_PATH/bin into your System $PATH. On the other hand, since JDK7 Update 21, the server JRE includes these tools IIRC as well.
  3. For Windows > Task Manager if PID is not displayed > click View - Select Columns > Select the PID (Process Identifier).
  4. Unix Terminal includes Linux and MacOS OS.
  5. As an option, for running Unix commands into Windows cygwin can be installed.
  6. Please check the KB Cloudbees Jenkins Platform supported Java versions.

References

Jps

Jstack

Jconsole

Jcmd

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.