DEV Community

The Tran
The Tran

Posted on

Get thread dump of Java container running on JRE Docker image

Given an webapp running with a JRE-based docker image in Kubernetes cluster, example: tomcat:9.0-jre11-temurin, then getting the thread dump is not easy as the JRE-based docker image does not include the tools like jstack, jmap...

We can use jattach tools to get our task done. TLDR; jattach is a compact tool written in C by Andrei Pangin.

First we need to download the tool to container:

Open the shell in the container:

kubectl -n default exec -it your-tomcat-pod -c your-tomcat-container -- bash
Enter fullscreen mode Exit fullscreen mode

Download the jattach to the working dir

cd /working-dir

curl -L -O https://github.com/apangin/jattach/releases/download/v2.2/jattach 

chmod +x jattach
Enter fullscreen mode Exit fullscreen mode

From your terminal create thread dump and store in the output file

kubectl -n default exec your-tomcat-pod \
  -c your-tomcat-container  -- \
  /working-dir/jattach 1 threaddump > thread-dump.txt
Enter fullscreen mode Exit fullscreen mode

Then you can use jstack.review tool to analyze the thread dump.

Image description

Top comments (0)