Operations 17 min read

Arthas Java Diagnostic Tool: Installation, Common Commands, and Usage Scenarios

This guide introduces Alibaba's open‑source Arthas tool for Java, explains when to use it, shows how to install it, and provides detailed examples of its most useful commands such as stack, jad, sc, watch, trace, jobs, logger, dashboard, and redefine for live JVM debugging and performance analysis.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Arthas Java Diagnostic Tool: Installation, Common Commands, and Usage Scenarios

Introduction

Arthas is an open‑source Java diagnostic tool from Alibaba that enables dynamic tracing of Java code and real‑time JVM monitoring without stopping the application. It supports JDK 6+ on Linux, macOS, and Windows.

This tool is very easy to use and highly recommended.

Usage Scenarios

Identify which JAR a class was loaded from and resolve class‑related exceptions.

Determine why modified code is not being executed (e.g., wrong branch or missing commit).

Debug issues that cannot be reproduced online without adding logs and redeploying.

Investigate data‑processing problems that occur only in production and cannot be reproduced locally.

Obtain a global view of system runtime status.

Monitor real‑time JVM performance metrics.

The following sections walk through Arthas' basic usage based on these six questions.

Installation

Download the boot JAR:

wget https://alibaba.github.io/arthas/arthas-boot.jar

Start it with java -jar and select the target Java process:

java -jar arthas-boot.jar

[INFO] Found existing java process, please choose one and hit RETURN.
* [1]: 79952 cn.test.MobileApplication
  [2]: 93872 org.jetbrains.jps.cmdline.Launcher

Enter the number of the process you wish to attach to and press Enter.

Common Commands

Current version: v3.1.4

[arthas@79952]$ version
3.1.4

1. stack

Displays the call stack of the current method, helping you locate which code paths invoke a particular method.

[arthas@79952]$ stack com.baomidou.mybatisplus.extension.service.IService getOne
Press Q or Ctrl+C to abort.
Affect(class-cnt:202 , method-cnt:209) cost in 10761 ms.
ts=2019-11-13 11:49:13;thread_name=http-nio-8801-exec-6;id=2d;is_daemon=true;priority=5;TCCL=org.springframework.boot.web.embedded.tomcat.TomcatEmbeddedWebappClassLoader@a6c54c3
    @com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.getOne()
        at com.baomidou.mybatisplus.extension.service.IService.getOne(IService.java:230)
        ...
        at cn.test.mobile.controller.order.OrderController.getOrderInfo(OrderController.java:500)

2. jad

Decompiles a loaded class to view its source code, useful for verifying whether the running code matches the expected version.

jad cn.test.mobile.controller.order.OrderController

Decompile a specific method:

jad cn.test.mobile.controller.order.OrderController getOrderInfo

ClassLoader:
@RequestMapping(value={"getOrderInfo"}, method={RequestMethod.POST})
public Object getOrderInfo(HttpServletRequest request, @RequestBody Map map) {
    ResponseVo responseVo = new ResponseVo();
    ...
}

3. sc (Search‑Class)

Searches for loaded classes by name pattern, helpful when you only remember part of a class name.

sc *OrderController*
cn.test.mobile.controller.order.OrderController

Show detailed class information with -d :

sc -d cn.test.mobile.controller.order.OrderController

 class-info        cn.test.mobile.controller.order.OrderController
 code-source       /F:/IDEA-WORKSPACE-TEST-qyb/trunk/BE/mobile/target/classes/
 name              cn.test.mobile.controller.order.OrderController
 isInterface        false
 ...

4. watch

Monitors method parameters and return values, allowing you to observe runtime data without modifying code.

watch cn.test.mobile.controller.order.OrderController getOrderInfo "{params,returnObj}" -x 2

Press Q or Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 456 ms.
ts=2019-11-13 15:30:18; [cost=18.48307ms] result=@ArrayList[
    @Object[][  # this is the param
        @RequestFacade[org.apache.catalina.connector.RequestFacade@1d81dbd7],
        @LinkedHashMap[isEmpty=false;size=2],
    ],
    @ResponseVo[  # this is the return object
        log=@Logger[Logger[cn.test.db.common.vo.ResponseVo]],
        success=@Boolean[true],
        message=@String[Ok],
        count=@Integer[0],
        code=@Integer[1000],
        data=@HashMap[isEmpty=false;size=1],
    ],
]

Use -b to observe before method execution (no return value yet).

5. trace

Shows the internal call chain of a method with timing information, useful for pinpointing performance bottlenecks.

trace -j cn.test.mobile.controller.order.OrderController getOrderInfo '#cost > 10'

Press Q or Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 96 ms.
---ts=2019-11-13 15:53:42;thread_name=http-nio-8801-exec-2;id=29;is_daemon=true;priority=5;TCCL=org.springframework.boot.web.embedded.tomcat.TomcatEmbeddedWebappClassLoader@a6c54c3
    ---[13.803743ms] cn.test.mobile.controller.order.OrderController:getOrderInfo()
        +---[0.01312ms] cn.test.db.common.vo.ResponseVo:
+---[0.01408ms] cn.test.mobile.controller.order.OrderController:getUserInfo()
        +---[12.675431ms] cn.test.db.service.IOrderMediaService:getOne()
        `---[0.409917ms] cn.test.db.common.vo.ResponseVo:setSuccess()

6. jobs

Runs commands asynchronously in the background and lists active jobs.

trace -j cn.test.mobile.controller.order.OrderController getOrderInfo > test.out &

jobs
[76]*  
       Running  trace -j cn.test.mobile.controller.order.OrderController getOrderInfo >> test.out &
       execution count : 0
       start time      : Wed Nov 13 16:13:23 CST 2019
       timeout date    : Thu Nov 14 16:13:23 CST 2019
       session         : f4fba846-e90b-4234-959e-e78ad0a5db8c (current)

Control job timeout with options job-timeout 2d and terminate with kill 76 .

7. logger

View and modify logger levels at runtime.

logger
 name                ROOT
 class               ch.qos.logback.classic.Logger
 classLoaderHash     18b4aac2
 level               INFO
 effectiveLevel      INFO

Update level to debug:

logger --name ROOT --level debug
update logger level success.

8. dashboard

Displays a real‑time overview of JVM metrics such as thread states, CPU usage, and memory statistics.

dashboard
ID    NAME                     GROUP    PRIORITY STATE   %CPU TIME   INTERRUPT DAEMON
17    Abandoned connection ... main      5      TIMED_WAI 0    0:0    false   true
... (additional thread rows) ...
Memory  used total max usage  GC
heap    216M 415M 3614M 5.99% gc.ps_scavenge.count 96
ps_eden_space 36M 78M 1276M 2.90% gc.ps_scavenge.time(ms) 3054
... (more memory rows) ...

9. redefine

Hot‑updates a loaded class without restarting the JVM.

jad --source-only cn.test.mobile.controller.order.OrderController > OrderController.java
sc -d cn.test.mobile.controller.order.OrderController | grep classLoaderHash
classLoaderHash   18b4aac2
mc -c 18b4aac2 OrderController.java -d ./
redefine -c 18b4aac2 OrderController.class
redefine success, size: 1

Other Notes

If you encounter port conflicts when launching java -jar arthas-boot.jar , select the correct process or use different telnet/http ports, e.g., java -jar arthas-boot.jar --telnet-port 9998 --http-port -1 , and shut down the conflicting process with the shutdown command.

Javaperformance analysisArthasJVM monitoringbackend debuggingdiagnostic tool
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

login 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.