preface

We have already talked about how to install Arthas, so today we will talk about the use of Arthas

A, preparation,

So we’re going to have to prepare a Java program that can’t be stopped once it’s started, so I’m going to use a simple loop and then I’m going to have a loop that keeps printing the value a

public class test { public static void main(String[] args) { int a = 1; while (a==1){ System.out.println(a); }}}

Second, the test

Under Windows test

Start the program and have it run in the background

Then click the menu key +R, run CMD to open the command line, and then enter the Arthas’ arthas-boot.jar directory. For example, mine is in disk D, so I need to enter the path of disk D first, and then CD can enter my directory

Once in the directory, use the following command to start Arthas

java -jar arthas-boot.jar

It will then display the test program that we just launched, and if you type 1 and press Enter to launch Arthas to test if you want to test any other Java program, just type the number before the program name

Of course, you can also monitor it in the browser. There is a link in the image above, and you can use the browser to execute the arthas command by entering the address in the browser

Three, execute,

Let’s run help first and see what the command is

Obviously, there are a lot of commands from Arthas, as we’ll see later

Let me introduce a few common ones first

Common commands

A clean up command is given ahead of time. The following common commands show too much stuff and need to be cleared out to make it look better

Clear on Windows, CLS on Linux

1. The dashborad dashboard

When you enter Dashborad, a table appears (if it doesn’t, it means the program is down and you want to keep the test running). This is called the Dashboard

The first is the state of all threads, the second is the memory usage, and the third is the state of the JVM and the information about Windows

These contents are refreshed and can be used to monitor the program and the Java virtual machine based on these data. Press Q or Ctrl+C to exit.

2. Thread thread plate

After typing this command, a table appears, similar to the first one above, showing all threads

Each thread is preceded by an ID, which can be viewed by the corresponding ID of Thread +

3. Jad decompiling

This command is a decompile command that decompiles the JAR package into code and displays it on the screen. For example, mine is a test program, so I type jad test

General procedures, you need to install the following steps to input

JAD package name

Several lines are returned, the first under red font is the class loader, the second is the path, the following is the source code and the decompilation time

4. Watch monitoring

You can see the return value of a function in this class. Here is the standard format

$watch package name. The class name and method name PrimeFactors returnObj

So I need to change my program to a function call, and now I change it to this, and it’s the same as before

public class test { public static void main(String[] args) { int a = 1; while (a==1){ System.out.println(outs(a)); } } public static int outs(int x){ return x; }}

So I’ll test the outs method, and again because I don’t have a package name in my program, I can omit the package name, so I’ll just type it in

$ watch test outs primeFactors returnObj

You can see that each time it will print a result, which is the expected “1”. It also tells you at the beginning that you can exit by pressing Q or Ctrl+C

You can also type $watch test outs primeFactors returnObj, but it will output the data in a loop. Press Q or Ctrl+C to exit the process

5. Quit Arthas

To simply exit the current connection, you can type quit or exit to exit the connection so that you can change the monitoring Java program

If I want to monitor test1 instead of test, print quit or exit to exit the connection and then reselect test1 to monitor.

I’m going to create a new Java program, test1, which has a similar function, but also prints a number in an infinite loop

public class test1 { public static void main(String[] args) { int a = 2; while (a==2){ System.out.println(a); }}}

At the same time, keep both programs running

Exit, and you can choose to monitor the other one. Sometimes there will be the case of failure to connect, this is because the port has just been occupied and has not been released, here you can just replace the port of test1, how to change the port is mentioned above

If you don’t want to exit Arthas, you just want to exit the monitor. How do you do that? If you want to exit Arthas, you need to use the stop command to close it



This is the end of the sharing, we will share more about the use of Arthas, stay tuned