一、官方文档
https://arthas.aliyun.com/doc/
二、基本使用
Arthas 相关命令:https://arthas.aliyun.com/doc/commands.html#arthas
启动一个Demo代码测试,编译后放到虚拟机上运行。
public class ArthasTest {
private static HashSet hashSet = new HashSet();
public static void main(String[] args) {
cpuHigh();
//deadThread();
//addHashSetThread();
}
public static void addHashSetThread() {
new Thread(() -> {
int count = 0;
while (true) {
try {
hashSet.add("count" + count);
Thread.sleep(1000);
count++;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
public static void cpuHigh() {
new Thread(() -> {
while (true) {
}
}).start();
}
private static void deadThread() {
Object resourceA = new Object();
Object resourceB = new Object();
Thread threadA = new Thread(() -> {
synchronized (resourceA) {
System.out.println(Thread.currentThread() + " get ResourceA");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread() + "waiting get resourceB");
synchronized (resourceB) {
System.out.println(Thread.currentThread() + " get resourceB");
}
}
});
Thread threadB = new Thread(() -> {
synchronized (resourceB) {
System.out.println(Thread.currentThread() + " get ResourceB");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread() + "waiting get resourceA");
synchronized (resourceA) {
System.out.println(Thread.currentThread() + " get resourceA");
}
}
});
threadA.start();
threadB.start();
}
}
启动 Arthas
java -jar arthas-boot.jar
执行命令后选择进程序号 1 或者直接回车
输入 dashboard 查看整个进程的运行情况,线程、内存、GC、运行环境信息。
输入 thread 查看线程详细情况
输入 thread加线程ID 查看线程堆栈
输入 thread -b 查看线程死锁
输入 jad加类的全名 反编译,可以方便查看线上代码是否是正确版本。
使用 ognl 命令查看线上系统变量的值,甚至可以修改变量的值。
文章仅供学习交流,侵权联系删除。