Arthas is an open source Java diagnostic tool for Alibaba. Troubleshoot faults online without restart. Dynamically trace Java code; Monitor JVM status in real time.

Testing in the local environment:

First, write an infinite loop in the program, repeatedly put the map, and then execute this code:

package com.sixj.demo;

import java.util.HashMap;
import java.util.Map;

/ * * *@author sixiaojie
 * @dateThe 2020-03-25 - its * /
public class TestArthas {
    public static void main(String[] args) {
        whileTrue();
    }
    private static void whileTrue(a){
        Map<String, Integer> map = new HashMap<>();
        / / death cycle
        while (true) {for (int i =0; i <= 100000; i++){ map.put(Thread.currentThread().getName()+i,i); }}}}Copy the code

Let’s start with Arthas:

Arthas – download demo. Jar:

curl -O https://alibaba.github.io/arthas/arthas-boot.jar
Copy the code

Then start with java-jar:

java -jar arthas-boot.jar
Copy the code

Arthas-boot is the arthas launcher. Once arthas is started, all Java processes are listed and the user can select the target process to diagnose.

Now you can see that the fifth one is the program you just started, type the number 5 and then Enter/ Press Enter and the Arthas LOGO will be printed. The first time you do this, you may need to download some resources, just wait a moment.

Enter Arthas and you can see that the login path has changed to [arthas@3007]$. You can enter Dashboard to go to the monitoring page.

CTRL + C exit the Dashboard interface and enter Thread 1 to view thread information, as shown in the following figure:

You can see that the whileTrue method in the TestArthas class is responsible for the CPU usage increase.

Using jad, Arthas’s built-in decompression method, type:

jad com.sixj.demo.TestArthas*
Copy the code

You can decompile Java’s class to see the code for the problem function, as shown below:

Finally enter the command: quit to exit Arthas

Official user documentation: alibaba. Making. IO/arthas