码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Arthas 排查JVM问题总结


    一、安装

    在Arthas官网:https://arthas.aliyun.com/中下载安装包。

    执行java -jar arthas-boot.jar就可以启动。

    image-20230908101838783

    二、常见命令

    • dashboard:查看JVM全局概览,包括线程、堆内存、GC还有系统信息等

    image-20230908004057353

    • thread:常见命令,查看线程。通过thread 查看线程详情信息。

    image-20230908004335178

    通过thread -b查看阻塞线程信息。

    image-20230908004426789

    • jad:反编译命令,能够将class文件反编译回源码。可以用在生产环境比较版本是否更新。

    image-20230908004631929

    • watch:查看方法参数

    • trace:查看方法内部调用路径,可以看到每条路径的耗时

    • stack:查看方法调用路径

    • redefine:将编译好的class热部署到环境

    • ognl:可以查看类中属性和方法执行情况。

    image-20230908005400528

    三、实践

    示例代码:

    public class Arthas {
    
        private static HashSet hashSet = new HashSet();
    
        public String getName() {
            return "arthas";
        }
    
        public static void main(String[] args) {
            // 模拟 CPU 过高
            cpuHigh();
            // 模拟线程死锁
            deadThread();
            // 不断的向 hashSet 集合增加数据
            addHashSetThread();
        }
    
        /**
         * 不断的向 hashSet 集合添加数据
         */
        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();
                    }
                }
            },"my-arthas-thread").start();
        }
    
        public static void cpuHigh() {
            new Thread(() -> {
                while (true) {
    
                }
            },"my-arthas-thread1").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");
                    }
                }
            },"my-arthas-thread2");
    
            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");
                    }
                }
            },"my-arthas-thread3");
            threadA.start();
            threadB.start();
        }
    }
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84

    查看死锁:

    通过thread -b查看死锁情况:

    image-20230908104407779

    查看CPU飙升:

    通过dashboard就能查看CPU占用情况:

    image-20230908104527155

    查看GC情况:

    通过dashboard就能查看GC情况:

    image-20230908104659145

    查看接口调用太慢:

    通过stack 来查看方法调用次数和时长。

    image-20230908105101387

    四、总结

    E4B52353-A4D1-413A-A98F-68658D32F749

    参考资料

    1. Arthas官网:https://arthas.aliyun.com/
    2. Arthas 使用详解:https://blog.csdn.net/zhangcongyi420/article/details/127252866
    3. 5-4-问题排查:https://www.pdai.tech/md/interview/x-interview.html#_5-4-问题排查

      本文由博客一文多发平台 OpenWrite 发布!

  • 相关阅读:
    模块化---common.js
    Python实现“黑猫投诉平台,舆论监控系统”
    从夜间照明到随动转向速锐得解码比亚迪唐车灯升级改装技术方案
    (g6)Radial 辐射布局
    ASP.NET Core框架探索之Authorization
    LLaMA-2 简介:开源大型语言模型的新篇章
    分类预测 | Matlab实现SO-RF蛇群算法优化随机森林多输入分类预测
    基于A*、RBFS 和爬山算法求解 TSP问题(Matlab代码实现)
    USB插座外壳接地的处理和emi,esd考虑
    vsCode设置文件注释和函数注释使用koroFileHeader插件
  • 原文地址:https://blog.csdn.net/ynkimage/article/details/132755878
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号