Skip to content

Taking and interpreting a JVM thread dump

Ricardo Mateus edited this page Nov 7, 2022 · 6 revisions

Introduction

Ever wanted to know what's going on exactly in the JVM, when a debugger is not available (eg. at a customer?)

A thread dump will provide an instant snapshot of all stacks, in all threads. Sometimes that is sufficient.

How to take a dump

zypper in java-11-openjdk-devel

# Tomcat
jstack `ps aux | grep catalina.startup | grep -v grep | awk '{print $2}'`
# Taskomatic
jstack `ps aux | grep TaskomaticDaemon | grep -v grep | awk '{print $2}'`

How to take several dumps

The following Bash script can be used to obtain Tomcat dumps every 5 seconds:

#!/bin/bash

mkdir /tmp/tomcat_thread_dump_monitor

while :
do
    jstack `ps aux | grep catalina.startup | grep -v grep | awk '{print $2}'` > /tmp/tomcat_thread_dump_monitor/`date --iso-8601=seconds`-dump.txt
    sleep 5
done

How to analyze dumps

One option can be intellij, which has a great feature for it. On intellij menu, go to Code -> Analyze Stack Trace or Thread Dump. This will open a window where one can past the thread dump data. If one does this with suma project opened in a branch with the same version where the thread dump was taken, it will provide links to classes inside the project.

Clone this wiki locally