Using Arthas to Diagnose High CPU Usage in Java Applications
This tutorial demonstrates how to download, attach, and use the Arthas Java diagnostic tool—leveraging commands like dashboard, thread, jad, watch, and ognl—to quickly locate and fix high CPU problems caused by parallel stream code in a Java application.
Arthas is an open‑source Java diagnostic tool from Alibaba that offers a more user‑friendly and powerful alternative to the built‑in JDK tools, allowing one‑click issue location, class decompilation, and even hot‑fixes in production.
First, download and start Arthas:
curl -O https://alibaba.github.io/arthas/arthas-boot.jar
java -jar arthas-boot.jarAfter launching, select the target JVM process; Arthas attaches successfully and displays process information.
The tutorial uses the following commands:
dashboard – shows overall thread, memory, and GC status
thread – displays thread stacks
jad – decompiles classes
watch – monitors method parameters and execution time
ognl – evaluates expressions
Running dashboard reveals that the high CPU usage is not caused by GC; eight threads consume most CPU, seven of which belong to ForkJoinPool.commonPool , indicating the problem lies in parallel‑stream code.
Using thread -n 8 shows the busiest threads, all processing MD5 operations, which explains the CPU consumption.
Decompiling HighCPUApplication with jad shows the call chain main → task() → doTask() ; when doTask receives a specific constant, it performs 10,000 MD5 calculations, causing the CPU spike.
To pinpoint the constant, the watch command monitors doTask calls whose execution time exceeds 100 ms and prints the parameters. All slow calls have the parameter 0 , suggesting the constant ADMIN_ID equals 0.
The ognl command confirms this by evaluating @org.geekbang.time.commonmistakes.troubleshootingtools.highcpu.User@ADMIN_ID , which returns 0 .
Note: commands like monitor , trace , and watch modify bytecode at runtime; after diagnosis, run shutdown to restore the original classes before exiting Arthas.
In this case, the problem was resolved by:
Using dashboard and thread to quickly identify the most CPU‑intensive threads.
Decompiling the relevant class with jad to locate the root cause.
Applying watch to observe method parameters and filter slow executions.
Besides Arthas, the article mentions the Qunar open‑source tool Bistoury , which provides a visual interface, multi‑machine management, and online breakpoint debugging.
The author also promotes his "Spring Cloud Alibaba Microservice Project Practice" series, inviting readers to subscribe via the provided QR code and WeChat ID special_coder .
Code Ape Tech Column
Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.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.