Thread Dumps

The following article is provided on an advice basis only. This article references third party software that may require licensing. A thread dump is a snapshot of exactly what is executing at a moment in time, across all of the Java threads that are currently active in a Java Virtual Machine (JVM).

Creating a thread dump

It is highly recommended to take more than one thread dump. A good practice is to take 10 thread dumps at regular intervals (for example, one thread dump every 10 seconds). Get the PID of your Java process. The Java JDK is packaged with the jps command which lists all Java process IDs. Run it as follows:

jps -l

Note: In Linux and UNIX, you may have to run this command as sudo -u user jps -l Where “user” is the username of the user that the Java process is running as. If this doesn’t work or you still cannot find your Java process, use the following.

  • UNIX, Linux and Mac OSX: ps -el | grep java
  • Windows: Press Ctrl+Shift+Esc to open the Task Manager and find the PID of the Java process.

We recommend using the jcmd tool to create your thread dumps. Use the following command to output the thread dump to a file rather than to the command line.

jcmd <pid> Thread.print >> threaddumps.log
  • The jcmd tool is available since JDK 1.7 and replaces tools such as jstack, which was previously used to take thread dumps from Java programs.
  • In Linux and UNIX, you might need to run this command as sudo -u user jcmd <pid> Thread.print >> threaddumps.log, where “user” is the user that the Java process is running as.

jcmd Script

The following script is a modified version of the script from eclipse.org, which will take a series of thread dumps using the jcmd tool.

#!/bin/bash
if [ $# -eq 0 ]; then
    echo >&2 "Usage: threadDumpSeries <pid> <run_user> [ <count> [ <delay> ] ]"
    echo >&2 "    Defaults: count = 10, delay = 0.5 (seconds)"
    exit 1
fi
pid=$1          # required
user=$2         # required
count=${3:-10}  # defaults to 10 times
delay=${4:-0.5} # defaults to 0.5 seconds
while [ $count -gt 0 ]
do
    sudo -u $user jcmd $pid Thread.print -l >jcmd.$pid.$(date +%H%M%S.%N)
    sleep $delay
    let count--
    echo -n "."
done

This script can then be run with the following command:

bash threadDumpSeries.sh [pid] [user] [count] [delay]

Sending to Push support

Once your thread dumps have been created, please compress the files and send to Push Technology Support. If the compressed files are too large to be emailed, please contact support, who will make alternative arrangements.