A tutorial on using Arthas

  • Arthas Download and Install (Linux)
curl -0https://alibaba.github,io/arthas/arthas-boot.jar
  • Arthas uninstallation (Linux)
rm -rf ~/.arthas/ install home directory 
rm -rf ~/logs/arthas logging directory 
  • Preparation before installation: You must run a Java process, run a Java program, or start your idea to start a Java process. Arthas will detect this process when starting, otherwise the following problem will be reported.
java -jar arthas-boot.jar 
  • If the port number is occupied, you can also use the following command to switch to another port number for execution.
java -jar arthas-boot.jar --telnet-port 9998 --http-port -1
  • The Arthas command must be used in the corresponding program.

Basic commands

  • Obtain the Main Class of the arthas demo process through thread command.
thread no threads id , with dashboard the effect is basically the same 
thread 1. can print threads ID stack of 1 
thread -n display the top 3 busiest threads currently and print the stack 
thread  b identify the threads currently blocking other threads, and sometimes we find that the application is stuck, usually due to 
 a certain thread has seized a lock, and other threads are waiting for the lock to cause it. in order to arrange 
 check for such issues, arthas provided thread -b find the culprit with just one click. 
thread --state WAITING view threads in a waiting state 
  • Decompile and view source code through jad.
 format 
jad package name . print the class name for all methods under this class 
jad package name . print the class name, method name, and the method below this class 

  • Viewing the return value of a method through the watch command.
watch package name . class name method name returnObj return value-- controller layers are generally not used 
  • Exit Arthas.
 if you are only exiting the current connection, you can use the quit perhaps exit command. Attach to the target process arthas it will continue to run, the port will remain open, and can be directly connected the next time. 
 if you want to completely exit arthas , can be executed stop command. 
  • Watch.
watch package name . class name method name returnObj return value-- controller layers are generally not used 

illustrate.

params represents all parameter arrays (as it is uncertain how many parameters they are), returnObject represents the return value 
watch demo.MathGame primeFactors "{params,returnObj}" -x 2
 grammar :watch package name . class name method"{params,returnObj}" -x 2       params: it can represent multiple or a single. 
  • Exit Watch.
 according to Q perhaps ctrl+c quit 
  • Jar command.
 decompile specified loaded class source code 
jad command will JVM actual operation in the middle class of byte code decompile into java code, easy for you to manage 
 understand business logic ;
 stay Arthas Console on the top, the decompiled source code is syntax highlighted, making it easier to read 
 of course, the decompiled version java there may be syntax errors in the code, but it does not affect your reading comprehension