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 the result 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

Do your career a favor. Join DEV. (The website you're on right now)

It takes one minute and it's free.

Get started

Top comments (0)

Great read:

Is it Time to go Back to the Monolith?

History repeats itself. Everything old is new again and I’ve been around long enough to see ideas discarded, rediscovered and return triumphantly to overtake the fad. In recent years SQL has made a tremendous comeback from the dead. We love relational databases all over again. I think the Monolith will have its space odyssey moment again. Microservices and serverless are trends pushed by the cloud vendors, designed to sell us more cloud computing resources.

Microservices make very little sense financially for most use cases. Yes, they can ramp down. But when they scale up, they pay the costs in dividends. The increased observability costs alone line the pockets of the “big cloud” vendors.

đź‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay