Backend Development 5 min read

Using Arthas for Java Hot Code Update and Runtime Debugging

This guide explains how to use Alibaba's Arthas tool to attach to a running Java process, inspect JVM metrics, execute hot code updates, and troubleshoot production issues without redeploying, covering download, common commands, and step‑by‑step hot‑swap procedures.

Java Captain
Java Captain
Java Captain
Using Arthas for Java Hot Code Update and Runtime Debugging

1. Introduction In production environments, adding log statements or fixing urgent bugs often requires redeploying, which can disturb the current state; hot‑update techniques allow developers to inject debugging code or apply patches without restarting the service.

2. Using Arthas Arthas is an open‑source Java diagnostic tool from Alibaba that can attach to a Java process to view JVM status and perform hot updates. To start it, download the boot JAR and run it:

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

After launching, Arthas lists all Java processes on the machine; select the target process by its number.

3. Common Commands The following commands are useful for diagnosing runtime issues:

dashboard    // real‑time system metrics
thread       // view JVM thread stack information
jvm          // display JVM details
sysprop      // view and modify JVM system properties
sysenv       // view JVM environment variables
getstatic    // view static fields of a class

Examples:

thread -n 5               // print top 5 CPU‑consuming threads
stack <full.class.Name> <method>   // view call stack of a method
trace <full.class.Name> <method>   // highlight the slowest sub‑call
monitor <full.class.Name> <method> // show call count, avg time, success rate
exit                     // leave the session (Arthas keeps running)
shutdown                 // completely stop Arthas

4. Hot Update Procedure

1) Identify the fully‑qualified class name and decompile the running code with jad :

jad --source-only <full.class.Name> > <outputDir/file.java>

2) Modify the source as needed. Note that hot‑update works via java.lang.instrument.Instrumentation.redefineClasses , which cannot add or remove fields/methods, and code inside non‑terminating loops will never take effect.

3) Locate the class loader of the target class:

sc -d <full.class.Name> | grep classLoaderHash

4) Compile the modified Java file in memory:

mc -c <classLoaderHash> <path/to/ModifiedFile.java>

5) Apply the hot‑swap with the redefine command:

redefine <path/to/ModifiedClass.class>

6) If the operation succeeds, the changes take effect immediately; verify the behavior accordingly.

5. Conclusion Arthas provides a powerful, non‑intrusive way to diagnose and hot‑replace Java code in production, enabling rapid debugging and emergency fixes without full redeployment.

BackendJavaInstrumentationArthasHot UpdateRuntime Debugging
Java Captain
Written by

Java Captain

Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.

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.