Mastering Arthas watch: Real‑time Method Call Inspection in Java
This tutorial demonstrates how to use Arthas' watch command to monitor Java method entry parameters and return values in real time, explains the required OGNL syntax, shows a practical demo code, and notes performance considerations for online debugging.
Arthas is an open‑source Java diagnostic tool that provides powerful runtime inspection capabilities.
Building on the previous article about the watch command, this piece focuses on practical usage within a demo application, illustrating how to apply the command to specific methods and how OGNL expressions are used to filter and format output. It also mentions that deeper performance‑monitoring features will be covered later with the trace command.
The watch command is especially useful for observing method arguments and return values during live debugging. Because it can introduce noticeable overhead, it is recommended to run it during off‑peak periods or in a controlled environment.
package com.fun;
import com.alibaba.fastjson.JSONObject;
import com.fun.frame.SourceCode;
import com.fun.utils.RString;
import org.slf4j.Logger;
public class Fun extends SourceCode {
int count;
public static Logger logger = getLogger(Fun.class);
public static void main(String[] args) {
Fun fun = new Fun();
while (true) {
fun.test();
sleep(1000);
output(RString.getStringWithoutNum(12));
sleep(1000);
JSONObject json = getJson("242=4324", "3242432=32423", "32432=dsdfdsf");
json.put("fun", json.clone());
json.put("fun", json.clone());
json.put("fun", json.clone());
json.put("fun", json.clone());
output(json);
try {
fun.fun();
} catch (Exception e) {
// handle exception
}
}
}
public void test() {
count++;
}
public String fun() {
sleep(getRandomInt(100));
int randomInt = getRandomInt(2);
if (randomInt == 1) fail();
return DEFAULT_STRING;
}
}The article concludes with a brief disclaimer about original content ownership and provides a contact email for collaboration, which is not essential to the technical discussion.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
