// 查看所有的logger [arthas@44455]$ logger name ROOT class ch.qos.logback.classic.Logger classLoader jdk.internal.loader.ClassLoaders$AppClassLoader@76ed5528 classLoaderHash 76ed5528 level INFO effectiveLevel INFO
// 死锁检测 [arthas@44455]$ thread -b "Thread-4" Id=80 BLOCKED on java.lang.Object@12ea72d3 owned by "Thread-5" Id=81 at app//cn.probiecoder.arthas_demo.TestController.lambda$0(TestController.java:89) - blocked on java.lang.Object@12ea72d3 - locked java.lang.Object@16629d6a <---- but blocks 1 other threads! at app//cn.probiecoder.arthas_demo.TestController$$Lambda/0x00007fa97475dcd0.run(Unknown Source) at java.base@21.0.6/java.lang.Thread.runWith(Thread.java:1596) at java.base@21.0.6/java.lang.Thread.run(Thread.java:1583)
// 根据状态过滤 [arthas@44455]$ thread --state BLOCKED Threads Total: 39, NEW: 0, RUNNABLE: 17, BLOCKED: 2, WAITING: 13, TIMED_WAITING: 7, TERMINATED: 0 ID NAME GROUP PRIORITY STATE %CPU DELTA_TI TIME INTERRU DAEMON 80 Thread-4 main 5 BLOCKED 0.02 0.000 0:0.002 false true 81 Thread-5 main 5 BLOCKED 0.01 0.000 0:0.002 false true
[arthas@44455]$ sysenv LANG KEY VALUE -------------------------------------------------------------------------------------------------------- LANG en_US.UTF-8
8、sysprop
查看或修改当前JVM 的系统属性
语法
1
sysprop [property-name] [property-value]
参数说明
参数名称
参数说明
property-name
属性名称,默认输出所有属性
property-value
属性修改后的值
使用示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
[arthas@44455]$ sysenv spring.profiles.active KEY VALUE -------------------------------------------------------------------------------------------------------- spring.profiles.active null [arthas@44455]$ sysprop spring.profiles.active dev Successfully changed the system property. KEY VALUE -------------------------------------------------------------------------------------------------------- spring.profiles.active dev
[arthas@44455]$ sysprop spring.profiles.active KEY VALUE -------------------------------------------------------------------------------------------------------- spring.profiles.active dev
9、vmoption
查看,更新 VM 诊断相关的参数,在更新option时,option需要支持运行时动态更新
语法
1
vmoption [name] [value]
参数说明
参数名称
参数说明
name
option的名称
value
修改后的值
使用示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// 查看指定option [arthas@44455]$ vmoption HeapDumpBeforeFullGC KEY VALUE ORIGIN WRITEABLE -------------------------------------------------------------------------------------------------------- HeapDumpBeforeFullGC false DEFAULT true // 修改指定option [arthas@44455]$ vmoption HeapDumpBeforeFullGC true Successfully updated the vm option. NAME BEFORE-VALUE AFTER-VALUE ------------------------------------------------- HeapDumpBeforeFullGC false true [arthas@44455]$ vmoption HeapDumpBeforeFullGC KEY VALUE ORIGIN WRITEABLE -------------------------------------------------------------------------------------------------------- HeapDumpBeforeFullGC true MANAGEMENT true
// 限制监听次数 [arthas@73802]$ watch -b -n 1 cn.probiecoder.arthas_demo.TestController hello {params[0],returnObj} Press Q or Ctrl+C to abort. Affect(class count: 1 , method count: 1) cost in 38 ms, listenerId: 29 method=cn.probiecoder.arthas_demo.TestController.hello location=AtEnter ts=2025-05-08 01:41:43.892; [cost=0.022054ms] result=@ArrayList[ @String[waw], null, ] Command execution times exceed limit: 1, so command will exit. You can set it with -n option.
三、后台任务
需要监控偶发性行为时,可以借助后台任务捕获,同时将捕获结果可以输出到文件
1、执行后台任务
在命令最后边添加 * 执行后台任务,命令不会阻断终端屏幕,可以继续执行其他任务
1
trace Class method &
2、查看后台任务
1
jobs
1 2 3 4 5 6 7
[arthas@252]$ jobs [10]* Running trace org.apache.aries.spifly.Util storeContextClassloader & execution count : 0 start time : Mon May 1219:33:48 CST 2025 timeout date : Tue May 1319:33:48 CST 2025 session : eb3cedf4-75a1-488c-af93-df3405ea7398 (current)