赞
踩
相关系列
Arthas是阿里在2018年9月开源的Java诊断工具。支持JDK6+,采用交互模式。可以很方便用于线上定位问题。官方文档地址:https://alibaba.github.io/arthas。
- #通过github下载arthas
- wget https://alibaba.github.io/arthas/arthas‐boot.jar
- #或者通过Gitee下载
- wget https://arthas.gitee.io/arthas‐boot.jar
执行指令java -jar ,arthas会自动识别出目前在机器运行的所有线程
- import java.util.HashSet;
-
- public class ArthasDemo {
-
- private static HashSet hashSet = new HashSet();
-
- 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);
- }catch (InterruptedException e){
- e.printStackTrace();
- }
- }
- }).start();
- }
-
- /**
- * cpu使用过高
- */
- public static void cpuHigh(){
- 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 deadThread(){
- Object objA = new Object();
- Object objB = new Object();
-
- Thread threadA = new Thread(()->{
- synchronized (objA){
- System.out.println(Thread.currentThread() + " get ResurceA");
- try{
- Thread.sleep(1000);
- }catch (InterruptedException e){
- e.printStackTrace();
- }
- System.out.println(Thread.currentThread() +"waiting get resourceB");
- synchronized (objB){
- System.out.println(Thread.currentThread() + " get resourceB");
- }
- }
- });
-
- Thread threadB = new Thread(()->{
- synchronized (objB){
- System.out.println(Thread.currentThread() + " get ResurceB");
- try{
- Thread.sleep(1000);
- }catch (InterruptedException e){
- e.printStackTrace();
- }
- System.out.println(Thread.currentThread() +"waiting get resourceA");
- synchronized (objA){
- System.out.println(Thread.currentThread() + " get resourceA");
- }
- }
- });
-
- threadA.start();
- threadB.start();
- }
- }
输入1,按回车
使用ognl命令修改变量的值
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。