Master Java Debugging with Alibaba Arthas: A Step‑by‑Step Guide

This tutorial walks through installing Alibaba Arthas, using it to monitor and analyze a Java Fibonacci application, and demonstrates key commands such as dashboard, thread, jad, monitor, watch, and profiler for effective performance debugging without code changes or restarts.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Java Debugging with Alibaba Arthas: A Step‑by‑Step Guide

Hello, I am Yuan, introducing Alibaba Arthas, a diagnostic tool that helps Java applications unleash their potential.

1. Introduction

Arthas is a Java diagnostic tool that can monitor, analyze, and solve problems in Java applications without modifying code or restarting the service.

2. Download and Getting Started

Download Arthas via curl or a direct link:

curl -O https://alibaba.github.io/arthas/arthas-boot.jar

Test it with the help option: java -jar arthas-boot.jar -h If successful, a help guide listing all commands is displayed.

3. Example Application

We use a simple Java program that computes the Fibonacci sequence recursively, which is intentionally inefficient to generate enough load for demonstration.

public class FibonacciGenerator {
    public static void main(String[] args) throws IOException {
        System.out.println("Press any key to continue");
        System.in.read();
        for (int i = 0; i < 100; i++) {
            long result = fibonacci(i);
            System.out.println(String.format("fib(%d): %d", i, result));
        }
    }
    public static long fibonacci(int n) {
        if (n == 0 || n == 1) {
            return 1L;
        } else {
            return fibonacci(n - 1) + fibonacci(n - 2);
        }
    }
}

4. Launch Arthas

Run the Fibonacci program, then start Arthas: java -jar arthas-boot.jar Arthas lists running Java processes; select the one named com.baeldung.arthas.FibonacciGenerator by entering its number.

[INFO] arthas-boot version: 3.1.7
[INFO] Found existing java process, please choose one and hit RETURN.
* [1]: 25500 com.baeldung.arthas.FibonacciGenerator
...

After attachment, a prompt appears where you can issue commands such as help and use tab completion.

5. Dashboard

Enter dashboard to view a detailed screen with panels showing thread information, CPU usage, memory statistics, garbage collector data, and JVM/host details.

6. Stack Trace Analysis

Use thread 1 to display the stack trace of the main thread, which is dominated by calls to fibonacci. Filter with grep to focus on specific frames.

thread 1 | grep 'main('

7. Decompile Java Classes

Run jad com.baeldung.arthas.FibonacciGenerator to decompile the class and view its source and metadata.

jad com.baeldung.arthas.FibonacciGenerator
...

8. Search Classes and Methods

Search loaded classes with sc *Fibonacci*, then use -d and -f flags for detailed info and fields. Search methods with sm com.baeldung.arthas.FibonacciGenerator and retrieve method signatures.

9. Monitor Method Calls

Use

monitor -c 10 com.baeldung.arthas.FibonacciGenerator fibonacci

to print performance metrics of the fibonacci method every 10 seconds.

10. Watch Method Parameters

Watch method arguments and return values with a condition, e.g.,

watch com.baeldung.arthas.FibonacciGenerator fibonacci '{params[0], returnObj}' 'params[0]>10' -n 10

This logs calls where the input exceeds 10, showing the parameter and result.

11. Profiler

Start the CPU profiler with profiler start, retrieve samples via profiler getSamples, and stop it with profiler stop. The generated flame graph highlights the Fibonacci thread as the main CPU consumer.

12. Summary

The tutorial demonstrated several powerful Arthas commands for diagnosing Java applications, especially when source code is unavailable or rapid troubleshooting on a production server is needed.

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.

JavaPerformance MonitoringdiagnosticsArthas
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.