How to Instantly Diagnose Java Production Issues with Arthas
This article introduces Arthas, an open‑source Java diagnostic tool, and demonstrates how to install it, use its command‑line and web console, and apply common commands such as dashboard, thread, watch, trace, and tt to quickly locate CPU spikes, deadlocks, memory leaks, and other production problems without redeploying code.
Introduction
Before using Arthas, diagnosing Java production issues required many commands (jps, jstack, jmap, etc.) which was cumbersome. Arthas simplifies locating problems such as CPU spikes, high load, memory leaks, allowing quick resolution.
1. What is Arthas
Arthas is an open‑source Java diagnostic tool released by Alibaba in September 2018. It supports JDK 6+ and provides an interactive command‑line interface with tab completion. The project has over 17 000 stars on GitHub.
Official documentation and issue examples are available on the GitHub repository.
Open‑source address: https://github.com/alibaba/arthas
Official docs: https://alibaba.github.io/arthas
2. Typical Use Cases
Get a global view of system status.
Identify which class or method is consuming CPU.
Detect deadlocks or blocked threads.
Measure method execution time.
Find the JAR that loaded a class.
Verify whether recent code changes are taking effect.
Debug without adding logs or redeploying.
Monitor JVM runtime metrics in real time.
3. How to Use Arthas
3.1 Installation
Download the arthas‑boot.jar from the official GitHub or Gitee mirror.
# github download
wget https://alibaba.github.io/arthas/arthas-boot.jar
# or Gitee download
wget https://arthas.gitee.io/arthas-boot.jar
# print help
java -jar arthas-boot.jar -h3.2 Running
Start the jar and select a Java process, or pass the PID directly.
# start and then choose PID
java -jar arthas-boot.jar
# or start with PID
java -jar arthas-boot.jar <pid>Use ps or jps to list Java processes.
After the Arthas logo appears you can issue diagnostic commands.
3.3 Web Console
Arthas also provides a Web Console accessible at http://127.0.0.1:8563/ with the same functionality as the terminal.
3.4 Common Commands
Some frequently used commands include:
dashboard – real‑time system overview.
thread – list thread information and CPU usage.
watch – observe method parameters and return values.
trace – show call stack and time spent per method.
stack – display the call chain of a method.
tt – time‑travel tunnel for method invocations.
monitor – periodic method execution statistics.
sc – view loaded class information.
sm – list methods of a class.
jad – decompile a loaded class.
classloader – inspect classloader hierarchy.
heapdump – generate a heap dump similar to jmap.
4. Practical Scenarios
4.1 Global Monitoring
Use dashboard to see threads, memory, GC, and environment data.
4.2 CPU Spike Diagnosis
Run thread to list all threads and their CPU usage; identify the thread with high CPU (e.g., ID 12).
Drill down with thread 12 or thread -n 10 to see top‑N CPU threads.
4.3 Thread‑Pool Status
Inspect thread‑pool threads with thread | grep pool to see WAITING threads.
4.4 Deadlock Detection
Run thread -b to display deadlock information.
4.5 Decompilation
Use jad com.Arthas to view source code of a loaded class.
4.6 Field and Method Inspection
Command sc -d -f com.Arthas shows fields; sm com.Arthas lists methods.
4.7 Variable Observation
Use ognl '@com.Arthas@hashSet' to inspect static variables, size, and modify them.
4.8 Performance Tracing
Apply trace com.UserServiceImpl get to see time spent in each sub‑method, identifying the most expensive part (e.g., mysql()).
4.9 Method Monitoring
Run monitor -c 5 com.UserServiceImpl get to collect execution statistics every 5 seconds.
4.10 Parameter Watching
Command watch com.Arthas addHashSet '{params[0],returnObj}' prints input and output of a method.
4.11 Call Stack
Use stack com.UserServiceImpl mysql to view the call chain.
4.12 Time‑Travel Tunnel
Start recording with tt -t com.UserServiceImpl check, list records with tt -l, view details with tt -i 1001, and replay a specific invocation using tt -i 1001 -p.
These commands enable developers to locate, analyze, and fix production issues without modifying code or restarting services.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Su San Talks Tech
Su San, former staff at several leading tech companies, is a top creator on Juejin and a premium creator on CSDN, and runs the free coding practice site www.susan.net.cn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
