How to generate a JVM thread dump?

The analysis of some problems requires having a thread dump of the JVM. This document explains how to generate a such thread dump.

Using script tnd-dump-threads

This script is available starting with release 20160229 which is the first release with an installer including an embedded JRE). For older releases, use the java tools directly as described below.

Execute the script <node dir>/bin/tnd-dump-threads.bat (Windows) or <node dir>/bin/tnd-dump-threads.sh (Linux).

If successful, the dump is written in a timestamped file in the <node dir>/var directory.

Example:

> <node dir>/bin/tnd-dump-threads.sh

threads dump generated in file <node dir>/var/dump_threads.20160225_163507.txt

Using directly the java tools

The generation of the thread dump is a two-step process:

The following steps require the use of a JDK or a Server JRE. If you only installed a JRE to run your node, you will not have access to the following tools.

1. Identify the PID of the java process

See How to identify the node process ID?

2. Generate the thread dump

Open a shell with the same user that is running the JVM to avoid OS security problems. Depending if jmap or jcmd is available, execute the following command, where $JAVA_HOME is the one that was used to launch the JVM to analyze (replace 32088 with the PID you found in the previous step):

$JAVA_HOME/bin/jstack -l 32088 > tdump.txt

or

$JAVA_HOME/bin/jcmd Thread.print -l 32088 > tdump.txt

The thread dump is written in the redirected file.

If the node is stuck, jstack may not respond. You may use the kill -3 pid command to stop the node and generate thread dump in the process standard output:

$JAVA_HOME/bin/kill -3 32088

Related Links