Master Java Troubleshooting with Arthas: Real‑World Scenarios and Commands

This article introduces Arthas, an open‑source Java diagnostic tool, explains its key features, demonstrates four practical troubleshooting scenarios with command examples, and shows how to start using it via an IDE plugin or direct download.

Alibaba Cloud Native
Alibaba Cloud Native
Alibaba Cloud Native
Master Java Troubleshooting with Arthas: Real‑World Scenarios and Commands

What is Arthas

Arthas is an open‑source, interactive command‑line tool for diagnosing Java applications at runtime. It runs inside the target JVM, provides a web console, and supports tab completion, making it easy to locate performance problems, thread deadlocks, class‑loading issues, and more without redeploying code.

Scenario 1: Identify CPU bottleneck during load testing

When CPU usage spikes, the thread command can reveal the busiest threads over a time window. thread -n 3 -i 10000 Parameters:

-n 3 – show the top 3 threads by CPU time.

-i 10000 – sample interval of 10 seconds.

The command prints the stack traces of the selected threads, allowing developers to pinpoint hot methods (e.g., excessive logging).

Scenario 2: Trace intermittent request timeouts

The trace command records method execution latency and can filter by a cost threshold. trace -t "methodName" -n 5 -c "cost>100" -t "methodName" – the method to monitor (wildcards are supported).

-n 5 – keep the latest 5 trace records.

-c "cost>100" – only output traces whose execution time exceeds 100 ms.

Running this on a suspect instance captures the latency distribution of the method, helping to locate the component that causes the timeout (e.g., synchronous logging).

Scenario 3: Debug dynamically generated bytecode

For classes generated at runtime (e.g., by ASM), the jad command decompiles the loaded class so its source can be inspected. jad com.example.GeneratedSerializer Combined with watch (to monitor field values or method calls) and mc / redefine (to modify bytecode on‑the‑fly), developers can diagnose and even hot‑patch generated code without restarting the JVM.

Scenario 4: Hot‑fix logging configuration without redeployment

When an expensive console appender is attached to Logback, it can be removed at runtime:

Identify the class loader hash of the target logger (example hash 5f205aa):

ognl -c 5f205aa '@org.slf4j.LoggerFactory@getLogger("root").aai.appenderList'

Delete the first appender (the console appender) from the list:

ognl -c 5f205aa '@org.slf4j.LoggerFactory@getLogger("root").aai.appenderList.remove(0)'

Optionally verify the change with sc -d ch.qos.logback.core.ConsoleAppender which disables the appender class.

Flame Graph for performance analysis

Arthas can generate a flame‑graph that visualises method‑level CPU consumption over a sampling period. Use the profiler command (or flamegraph in newer versions) to collect samples and then view the generated SVG in a browser.

profiler start
# run workload for a few seconds
profiler stop
profiler export --type flamegraph

Getting Started with Arthas

Two common ways to obtain and run Arthas:

Direct download : Clone or download the official repository https://github.com/alibaba/arthas. The easiest way to launch Arthas against a running JVM is:

curl -L https://arthas.aliyun.com/arthas-boot.jar | java -jar /dev/stdin

This attaches to the target JVM and opens an interactive console.

IDE integration : The Cloud Toolkit plugin for IntelliJ IDEA (and other IDEs) bundles Arthas, allowing one‑click remote diagnostics. The underlying command set is identical to the standalone version.

All commands are executed inside the Arthas console; use help to list available commands and exit to quit.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DebuggingJavaPerformance MonitoringdiagnosticsArthasIDE plugin
Alibaba Cloud Native
Written by

Alibaba Cloud Native

We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.