Home >Java >javaTutorial >Get thread dump of Java container running on JRE Docker image

Get thread dump of Java container running on JRE Docker image

Patricia Arquette
Patricia ArquetteOriginal
2024-11-03 22:24:31594browse

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

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

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

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

Get thread dump of Java container running on JRE Docker image

The above is the detailed content of Get thread dump of Java container running on JRE Docker image. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn