栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java诊断工具Arthas

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java诊断工具Arthas

目录
  • 一、官方文档
  • 二、基本使用

一、官方文档

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 命令查看线上系统变量的值,甚至可以修改变量的值。

文章仅供学习交流,侵权联系删除。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/948911.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号