开源Java诊断工具,采用命令行交互模式,可方便的定位和诊断线上程序运行问题。
Arthas使用
wget https://alibaba.github.io/arthas/arthas‐boot.jar
wget https://arthas.gitee.io/arthas‐boot.jar
# 下载结束后,使用java -jar启动即可
测试代码
package io;
import java.util.HashSet;
public class Arthas {
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();
}
public static void deadThread() {
Object resourceA = new Object();
Object resourceB = new Object();
Thread threadA = new Thread(() -> {
synchronized (resourceA) {
System.out.println(Thread.currentThread() + " get ResourcesA");
try {
Thread.sleep(1000);
} cat