preface

Before we have talked about how to use Arthas on Windows, today we are going to talk about the use of Arthas on Linux

A, preparation,

We also need to prepare a Java program, after the start of the cannot stop, then I will use an endless loop program, the following is an endless loop program, always output a value

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

Second, the test

Linux under test

Linux and Windows use the same steps, but you need to start the JAR package, you first put the program JAR package in the Arthas directory, use FTP transfer can be

If you do not have FTP transfer tools, you can follow our official account: full stack development Dream, reply 2 to get the download link

After the upload is complete, use the command to start the jar. For example, mine is test.jar. After I put it, enter the jar directory and use the following command line to start

java -jar test.jar

And then I’m going to let this program run here without closing it, and I’m going to open up another window and launch Arthas

Go to the Arthas directory and type the startup command. The command is as follows

java -jar arthas-boot.jar

Again, select the number before test to start Arthas

If you want to detect another Java program, enter the number that precedes the program name

Sometimes a port may be used and a different port may need to be executed

java -jar arthas-boot.jar --telnet-port 9988 --http-port -1

Of course Linux can also access Arthas from a browser, but only on the built-in Web, not outside Windows browsers, if you use Windows browsers to access the link will not be found

Three, execute,

Let’s start by executing help, which will show the same command as on Windows

Common commands

As mentioned in the previous post, the same commands that Windows uses are also available on Linux

The cleanup command is also available

Clear for Windows, CLS for Linux

1. The dashborad dashboard

After you enter Dashborad, you’ll also see information from the dashboard for a review

The dashboard has three main sections, the first is the state of all the 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 thread board will also appear, which is similar to the Windows function in the previous article, showing all the threads

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

3. Jad decompiling

JAD: Test1. If I type JAD test, it will say that the class was not found because my class name is test1. If I type JAD test, it will say that the class was not found because my class name is test1

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

JAD package name

After I type in JAD test1, it will decompile the file of my class and display it here

To recap, the first is the class loader in red, the second is the path, and the following is the source code and decompilation time

4. Watch monitoring

You can see the return value of a function in this class, so I will briefly talk about the format, and I will not change it. The format of the general command is as follows. Only if there is a method (function) in this class, can you use this command

Watch the package name. The class name and method name PrimeFactors returnObj

Because I said in front of the Windows will no longer change, small partners on their own back to try it, the following is the code of the last article

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; }}

To test the outs method, omit the package name without the package name, so I’ll just type 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 say watch test outs primeFactors returnObj instead of primeFactors, and it will output data, but it will output data in a loop, every time it’s done, and the output will say what type it is, For example, for the Integer type here, press Q or Ctrl+C to exit

5. Quit Arthas

I will not repeat what I said in the last article, but quit or exit is used to exit monitoring, and stop is used to exit the whole program like Arthas, remember that.

If you don’t remember how to spell a word, don’t worry, as long as you remember the first few words, if you forget the back of the Tap key will automatically help you fill in oh

This is the end of the share, later will share more about the use of Arthas, please look forward to oh