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 big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

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

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay