Simple Guide to Using Arthas

Introduction to Arthas
Arthas is a powerful Java diagnostic tool open-sourced by Alibaba in September 2018. It supports JDK 6 and above, provides an interactive command-line interface, supports multiple platforms (Linux/Mac/Windows), and features Tab auto-completion. Arthas enables developers to quickly diagnose and locate production issues in Java applications without modifying code or restarting services.
Why Do We Need Arthas?
In daily development, traditional methods are inefficient when encountering the following Java issues:
- High CPU load, but unable to locate specific threads
- Thread deadlocks causing system freeze, difficult to view thread status in real-time
- Slow application response, unclear method call chains
- Production code inconsistent with expectations, code not taking effect after hot deployment
- Remote debugging prohibited in production environments, unable to view variables in real-time
- Lack of real-time JVM status and performance monitoring ::
Due to these pain points, Arthas was created to help developers achieve problem location, real-time monitoring, and code hot-swapping.
Installing and Starting Arthas
Installation
The simplest method is to download the official arthas-boot.jar:
::tab{
=’[“GitHub”, “Gitee”]’} #tab1# Download from GitHub
curl -O https://arthas.aliyun.com/arthas-boot.jar#tab2
# Recommended for users in China - download from Gitee
curl -O https://arthas.gitee.io/arthas-boot.jar::
Starting
Start using the java -jar command:
::tab{
=’[“Interactive Mode”, “Specify PID”]’} #tab1# Start Arthas and select Java process
java -jar arthas-boot.jar#tab2
# Or directly specify process PID
java -jar arthas-boot.jar [PID]::
After running, it will list Java processes on the system. Select the process number you need to diagnose.
Common Arthas Commands
Arthas has a rich set of commands, which can be categorized as follows:
::tab{
=’[“Basic Commands”, “Monitoring Commands”, “Class Operations”, “Enhancement Commands”]’} #tab1| Command | Description |
|---|---|
help | View command help information |
cat | Print file content |
grep | Search for matching results |
pwd | Return current working directory |
cls | Clear current screen |
session | View current session information |
reset | Reset class enhancement state |
version | Output current Arthas version |
quit | Exit current client |
shutdown | Shutdown Arthas server |
#tab2
| Command | Description |
|---|---|
dashboard | Display current system real-time data panel |
thread | View JVM thread stack information |
jvm | View JVM information |
sysprop | View and modify JVM system properties |
sysenv | View JVM environment variables |
vmoption | View and modify JVM diagnostic options |
perfcounter | View JVM performance counter information |
logger | View and modify logging levels |
#tab3
| Command | Description |
|---|---|
sc | View loaded class information |
sm | View class method information |
jad | Decompile loaded class source code |
mc | Compile Java file to Class file in memory |
redefine | Redefine loaded classes |
dump | Export bytecode of loaded classes |
classloader | View classloader hierarchy, paths, etc. |
#tab4
| Command | Description |
|---|---|
monitor | Method execution monitoring |
watch | Monitor method input parameters and return values |
trace | Trace method call path and time consumption |
stack | Output current method call path |
tt | Time tunnel for recording method call parameters and return values |
| :: |
Practical Use Cases
Case 1: Locate Threads with High CPU Usage
Locate specific threads and stacks consuming resources.
Case 2: Troubleshoot Slow Application Response
Use the trace command to trace interface method calls and find the most time-consuming methods.
Case 3: View Class Loading Information
sc -d ClassName views detailed loading information for a specified class, including class loading path and classloader, helping troubleshoot class loading exceptions.
Case 4: Detect and Fix Thread Deadlocks
Locate threads waiting for each other’s locks.
Case 5: Observe Method Input Parameters and Return Values
View method call parameters and return values in real-time, facilitating debugging and understanding business behavior.
Arthas Web Console
Arthas provides a graphical Web Console. After starting Arthas, visit: http://127.0.0.1:8563/
The Web Console has the same functionality as the command line, supports command history and real-time feedback, facilitating team collaboration and troubleshooting.
Important Notes
- Arthas is a diagnostic tool. Use with caution in production environments, requiring approval. Avoid operations during peak hours.
- Some commands (such as trace, watch, tt) modify bytecode and may affect performance. Long-term running may bring memory leak risks.
- Enhanced classes will be automatically reset when Arthas exits. You can manually execute the
resetcommand. - Strict permission control and operation logging should be implemented when using in production environments. ::
Summary
Through this article, you have mastered the basics and practical applications of Arthas, enabling you to efficiently troubleshoot Java production issues and improve tuning capabilities. It is recommended to practice more in projects to gradually master this powerful tool.
title: Arthas Official Documentation link: https://arthas.aliyun.com/doc/
::
title: Arthas GitHub Repository link: https://github.com/alibaba/arthas
::
title: Arthas Online Tutorials link: https://arthas.aliyun.com/doc/arthas-tutorials.html
::
title: Arthas Community Forum link: https://github.com/alibaba/arthas/discussions
::