<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Java on AsherSu's Blog</title><link>https://ashersu.cn/en/categories/java/</link><description>Recent content in Java on AsherSu's Blog</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><lastBuildDate>Mon, 12 Oct 2026 20:09:00 +0800</lastBuildDate><atom:link href="https://ashersu.cn/en/categories/java/index.xml" rel="self" type="application/rss+xml"/><item><title>A Practical Arthas Workflow for Troubleshooting Java in Production</title><link>https://ashersu.cn/en/posts/arthas-online-troubleshooting/</link><pubDate>Mon, 12 Oct 2026 20:09:00 +0800</pubDate><guid>https://ashersu.cn/en/posts/arthas-online-troubleshooting/</guid><description>&lt;p&gt;When an API suddenly becomes slow, restarting the service should not be the first response. A restart may temporarily restore service, but it also destroys the most valuable runtime evidence. Arthas can inspect a running JVM without changing application code.&lt;/p&gt;&#10;&lt;h2 id="confirm-the-scope"&gt;&lt;a href="#confirm-the-scope" class="header-anchor"&gt;&lt;/a&gt;Confirm the scope&#13;&#10;&lt;/h2&gt;&lt;p&gt;Before running commands, record:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;The affected APIs or jobs.&lt;/li&gt;&#10;&lt;li&gt;When the problem started and whether traffic changed.&lt;/li&gt;&#10;&lt;li&gt;CPU, memory, GC, thread pool, and database connection pool metrics.&lt;/li&gt;&#10;&lt;li&gt;Recent releases, configuration changes, and downstream failures.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Every command should test a hypothesis. Avoid enabling expensive observation on high-frequency production methods without limits.&lt;/p&gt;&#10;&lt;h2 id="inspect-the-jvm-and-threads"&gt;&lt;a href="#inspect-the-jvm-and-threads" class="header-anchor"&gt;&lt;/a&gt;Inspect the JVM and threads&#13;&#10;&lt;/h2&gt;&lt;p&gt;Use &lt;code&gt;dashboard&lt;/code&gt; for a high-level view of threads, heap usage, and GC. Then inspect high-CPU or blocked threads:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;&#10;&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1&#10;&lt;/span&gt;&lt;span class="lnt"&gt;2&#10;&lt;/span&gt;&lt;span class="lnt"&gt;3&#10;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#10;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;dashboard&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;thread -n 10&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;thread --state BLOCKED&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;&lt;p&gt;If many threads wait for the same lock, inspect their stacks. If they are waiting on remote calls, move the investigation toward downstream latency, timeouts, and connection pools.&lt;/p&gt;&#10;&lt;h2 id="locate-slow-methods"&gt;&lt;a href="#locate-slow-methods" class="header-anchor"&gt;&lt;/a&gt;Locate slow methods&#13;&#10;&lt;/h2&gt;&lt;p&gt;&lt;code&gt;trace&lt;/code&gt; shows the time spent at each node in a call chain:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;&#10;&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1&#10;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#10;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;trace com.example.OrderService queryOrder &amp;#39;#cost &amp;gt; 100&amp;#39;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;&lt;p&gt;Filtering by execution time reduces noise and runtime overhead. After identifying a suspicious method, use &lt;code&gt;watch&lt;/code&gt; to inspect only the necessary arguments, return values, or exceptions.&lt;/p&gt;&#10;&lt;p&gt;Always limit the number of observations and output depth. Avoid printing large objects or observing extremely hot methods.&lt;/p&gt;&#10;&lt;h2 id="verify-the-loaded-code"&gt;&lt;a href="#verify-the-loaded-code" class="header-anchor"&gt;&lt;/a&gt;Verify the loaded code&#13;&#10;&lt;/h2&gt;&lt;p&gt;When a release appears not to have taken effect, use &lt;code&gt;sc&lt;/code&gt;, &lt;code&gt;sm&lt;/code&gt;, and &lt;code&gt;jad&lt;/code&gt; to inspect loaded classes, methods, and decompiled bytecode. The &lt;code&gt;classloader&lt;/code&gt; command helps identify which class loader loaded a class.&lt;/p&gt;&#10;&lt;h2 id="build-an-evidence-chain"&gt;&lt;a href="#build-an-evidence-chain" class="header-anchor"&gt;&lt;/a&gt;Build an evidence chain&#13;&#10;&lt;/h2&gt;&lt;p&gt;A useful incident conclusion connects monitoring symptoms, thread or trace evidence, the root cause, immediate mitigation, and the permanent fix. For example, an apparently slow Java method may ultimately be waiting for an exhausted database connection pool.&lt;/p&gt;&#10;&lt;p&gt;Arthas shortens the distance between a symptom and runtime evidence. Use the smallest observation scope possible and record the commands, timestamps, and conclusions for the incident review.&lt;/p&gt;&#10;</description></item></channel></rss>