深度解析阿里Arthas:从入门到精通,掌握Java应用问题排查利器( 二 )

$ jvm com.example.demo.User其中,com.example.demo.User表示类名 。
输出:
Class: com.example.demo.UserLoaded Count: 1Instance Count: 1Total Count: 17、调试Java应用使用以下命令可以在Java应用中进行调试:

  • 打开Java应用的调试端口:
$ jad --source-only com.example.demo.DemoController hello其中,
com.example.demo.DemoController表示类名,hello表示方法名 。
输出:
$ jad --source-only com.example.demo.DemoController helloDecompiled code of com.example.demo.DemoController#hello is as follows:
  • 使用调试器连接Java应用的调试端口:
$ jdb -attach 127.0.0.1:80008、其他命令除了以上介绍的命令之外,Arthas还提供了一些其他有用的命令,例如:
  • 查看Java类的字节码:
$ sc com.example.demo.DemoController其中,
com.example.demo.DemoController表示类名 。
输出:
Class: com.example.demo.DemoControllerClassLoader: sun.misc.Launcher$AppClassLoader@18b4aac2Location: file:/Users/arthas/arthas-demo/target/classes/Code Source: file:/Users/arthas/arthas-demo/target/classes/Super Class: org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
  • 查看Java类的加载情况:
$ classloader输出:
ClassLoader tree:sun.misc.Launcher$AppClassLoader@18b4aac2+- sun.misc.Launcher$ExtClassLoader@6cd87312
  • 查看当前系统的环境变量:
 $ env输出:
PATH: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin查看当前的工作目录:$ pwd输出:
/Users/arthas
  • 查看当前的Java版本:
$ version输出:
openjdk version "1.8.0_212"OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_212-b03)OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.212-b03, mixed mode)
  • 1.
  • 2.
  • 3.
  • 退出Arthas:
$ quit输出:
Bye! Enjoy the day, enjoy the life~以上是Arthas的一些常用命令,可以帮助开发者快速定位和解决Java应用中的问题 。当然,Arthas还有许多其他的功能和命令,这里只是介绍了一部分,感兴趣的读者可以查看官方文档或者自行探索 。

【深度解析阿里Arthas:从入门到精通,掌握Java应用问题排查利器】


推荐阅读