<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: The Tran</title>
    <description>The latest articles on DEV Community by The Tran (@tranthe).</description>
    <link>https://dev.to/tranthe</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1782169%2F62e50a73-50a0-4206-8383-3db319020bb2.jpg</url>
      <title>DEV Community: The Tran</title>
      <link>https://dev.to/tranthe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tranthe"/>
    <language>en</language>
    <item>
      <title>Get thread dump of Java container running on JRE Docker image</title>
      <dc:creator>The Tran</dc:creator>
      <pubDate>Fri, 01 Nov 2024 02:38:29 +0000</pubDate>
      <link>https://dev.to/tranthe/get-thread-dump-of-java-container-running-on-jre-docker-image-39lk</link>
      <guid>https://dev.to/tranthe/get-thread-dump-of-java-container-running-on-jre-docker-image-39lk</guid>
      <description>&lt;p&gt;Given an webapp running with a JRE-based docker image in Kubernetes cluster, example: &lt;code&gt;tomcat:9.0-jre11-temurin&lt;/code&gt;, then getting the thread dump is not easy as the JRE-based docker image does not include the tools like &lt;code&gt;jstack&lt;/code&gt;, &lt;code&gt;jmap&lt;/code&gt;...&lt;/p&gt;

&lt;p&gt;We can use &lt;a href="https://github.com/apangin/jattach" rel="noopener noreferrer"&gt;jattach&lt;/a&gt; tools to get our task done. &lt;code&gt;TLDR;&lt;/code&gt; &lt;code&gt;jattach&lt;/code&gt; is a compact tool written in C by Andrei Pangin.&lt;/p&gt;

&lt;p&gt;First we need to download the tool to container:&lt;/p&gt;

&lt;p&gt;Open the shell in the container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl &lt;span class="nt"&gt;-n&lt;/span&gt; default &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; your-tomcat-pod &lt;span class="nt"&gt;-c&lt;/span&gt; your-tomcat-container &lt;span class="nt"&gt;--&lt;/span&gt; bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Download the jattach to the working dir&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /working-dir

curl &lt;span class="nt"&gt;-L&lt;/span&gt; &lt;span class="nt"&gt;-O&lt;/span&gt; https://github.com/apangin/jattach/releases/download/v2.2/jattach 

&lt;span class="nb"&gt;chmod&lt;/span&gt; +x jattach
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From your terminal, create thread dump and store the result in the output file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl &lt;span class="nt"&gt;-n&lt;/span&gt; default &lt;span class="nb"&gt;exec &lt;/span&gt;your-tomcat-pod &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-c&lt;/span&gt; your-tomcat-container  &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  /working-dir/jattach 1 threaddump &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; thread-dump.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you can use &lt;a href="https://jstack.review/" rel="noopener noreferrer"&gt;jstack.review&lt;/a&gt; tool to analyze the thread dump.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8z1mqj9ox25uzufvpws0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8z1mqj9ox25uzufvpws0.png" alt="Image description" width="800" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>java</category>
      <category>threaddump</category>
    </item>
  </channel>
</rss>
