Skip to content

Taking and interpreting a JVM thread dump

Silvio Moioli edited this page Dec 18, 2020 · 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
Clone this wiki locally