Backend Development 7 min read

Master Real-Time Java Debugging with Arthas: From Issue Detection to Hot Swapping

This guide explains how to use Arthas for fast problem location in Java services, demonstrates watch commands, shows one‑click installation, and introduces the ArthasHotSwap plugin for hot code deployment while warning against production misuse.

Dangbei Technology Team
Dangbei Technology Team
Dangbei Technology Team
Master Real-Time Java Debugging with Arthas: From Issue Detection to Hot Swapping

Preface

When a production issue cannot be reproduced in test or pre‑release environments, adding logs across the whole pipeline is inefficient. A powerful debugging tool like Arthas can provide a "god view" of method inputs and outputs to quickly pinpoint problems.

1. Quick Problem Location

1) Locate the interface method

The following sample code checks a video’s status; it returns success only when both approval and status checks are true.

<code>@Override
public SingleResponse<Boolean> check(Long videoId) {
    boolean approvalCheck = this.approvalCheck(videoId);
    boolean statusCheck = this.statusCheck(videoId);
    return SingleResponse.of(approvalCheck && statusCheck);
}

private Boolean statusCheck(Long videoId) {
    // simulate status check
    return Boolean.TRUE;
}

private Boolean approvalCheck(Long videoId) {
    // simulate approval check
    return Boolean.FALSE;
}</code>

The symptom is that testers see a true video status but the interface returns false, with no logs to indicate the failing line. Using Arthas’s

watch

command can observe method parameters and return values.

2) Generate the watch command

Install the "Arthas IDEA" plugin (see image) and right‑click the target method to select watch .

3) Run Arthas

Arthas can be installed on Linux/Unix/Mac with a single command:

<code>curl -L https://arthas.aliyun.com/install.sh | sh</code>

The script downloads

as.sh

; place it in

$PATH

and run

./as.sh

to enter the interactive console.

4) Execute the watch command

<code>watch com.*.*.app.service.AssetServiceImpl check '{params,returnObj,throwExp}' -n 5 -x 3 'params[0]==123'</code>

Explanation:

com.*.*.app.service.AssetServiceImpl : fully qualified class name.

check : method to monitor.

{params,returnObj,throwExp} : observe parameters, return value, and thrown exception.

-n 5 : stop after 5 observations.

-x 3 : limit printed nested structure to 3 levels.

'params[0]==123' : condition filter.

5) Re‑request

With

params[0]=123

, the method returns

data=false

. The watch output reveals that

approvalCheck

returns false, which is the root cause.

2. Code Hot Deployment

After identifying a code issue, instead of redeploying after a long wait, use the ArthasHotSwap plugin. Install it from the IDEA plugin marketplace.

Workflow: modify code → local compile → select Swap this class → log into remote server → paste generated command → hot‑swap succeeds.

Warning: Never perform hot updates in production. Hot‑swap is a development‑efficiency tool, not a solution for live issues.

The plugin relies on Arthas’s

redefine

command, which uses the JDK Instrumentation API. Limitations include inability to rename classes or methods, add new fields, add non‑static methods, or modify inner‑class bytecode.

3. Summary

The examples above cover only a fraction of Arthas’s capabilities. For deeper learning, consult the official documentation and GitHub repositories.

Reference Links

https://arthas.gitee.io https://www.yuque.com/arthas-idea-plugin/help/pe6i45 https://github.com/alibaba/arthas/issues?q=label%3Auser-case
backend developmentruntime monitoringArthasJava debugginghot swap
Dangbei Technology Team
Written by

Dangbei Technology Team

Dangbei Technology Team public account

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.