掃二維碼與項目經(jīng)理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
Arthas是阿里開源的一款Java診斷工具,支持在線排查Java應(yīng)用問題。它能夠幫助Java開發(fā)者快速定位并解決生產(chǎn)環(huán)境中的各種問題,例如性能問題、死鎖問題、內(nèi)存泄漏問題等。

10余年的呼和浩特網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。成都全網(wǎng)營銷的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整呼和浩特建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)建站從事“呼和浩特網(wǎng)站設(shè)計”,“呼和浩特網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。
以下是Arthas教程的詳細介紹,包括每個使用知識點的實例命令和輸出:
首先需要下載Arthas并安裝,具體操作可以參考Arthas的官方文檔。
在Arthas安裝完成后,使用以下命令連接目標Java進程:
$ java -jar arthas-boot.jar
$ attach PID
其中,PID是目標Java進程的進程ID。
輸出:
成功連接到目標Java進程。
使用以下命令可以查看Java類的信息:
$ class com.example.demo.DemoController
輸出:
class com.example.demo.DemoController
$ method com.example.demo.DemoController
輸出:
com.example.demo.DemoController
public java.lang.String com.example.demo.DemoController.hello(java.lang.String)
public void com.example.demo.DemoController.handleException()
$ field com.example.demo.DemoController
輸出:
com.example.demo.DemoController
private static final org.slf4j.Logger com.example.demo.DemoController.logger
使用以下命令可以監(jiān)控Java方法的執(zhí)行情況:
$ monitor -c 5 com.example.demo.DemoController hello
其中,-c 5表示監(jiān)控5次方法執(zhí)行情況,
com.example.demo.DemoController表示類名,hello表示方法名。
輸出:
Monitoring com.example.demo.DemoController#hello for 5 times, interval: 1s, timeout: 300s.
Press Ctrl+C to abort.
Execution count: 1, Total cost: 43.291 ms, Avg cost: 43.291 ms, Min cost: 43.291 ms, Max cost: 43.291 ms, Exception count: 0, TPS: 23.13/s
Execution count: 2, Total cost: 41.117 ms, Avg cost: 41.117 ms, Min cost: 41.117 ms, Max cost: 41.117 ms, Exception count: 0, TPS: 24.36/s
Execution count: 3, Total cost: 39.304 ms, Avg cost: 39.304 ms, Min cost: 39.304 ms, Max cost: 39.304 ms, Exception count: 0, TPS: 25.42/s
Execution count: 4, Total cost: 41.825 ms, Avg cost: 41.825 ms, Min cost: 39.304 ms, Max cost: 43.291 ms, Exception count: 0, TPS: 23.91/s
Execution count: 5, Total cost: 42.246 ms, Avg cost: 49.2 ms, Min cost: 39.304 ms, Max cost: 83.554 ms, Exception count: 0, TPS: 24.44/s
$ monitor -c 5 com.example.demo.DemoController
其中,-c 5表示監(jiān)控5次方法執(zhí)行情況,
com.example.demo.DemoController表示類名。
輸出:
Monitoring com.example.demo.DemoController for 5 times, interval: 1s, timeout: 300s.
Press Ctrl+C to abort.
Execution count: 2, TPS: 1.0/s
Execution count: 2, TPS: 1.0/s
Execution count: 2, TPS: 1.0/s
Execution count: 2, TPS: 1.0/s
Execution count: 2, TPS: 1.0/s
使用以下命令可以查看Java線程的信息:
$ thread
輸出:
Id Group State Name
1 main RUNNABLE ...
2 main WAITING ...
3 main TIMED_WAITING ...
4 main BLOCKED ...
$ thread 1
其中,1表示線程ID。
輸出:
Thread[main,5,main]
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:216)
使用以下命令可以查看Java內(nèi)存的信息:
$ jvm
輸出:
Class Loaders: 7
Loaded Classes: 13198
Total Classes: 13241
Heap Memory Usage: init:2621440, used:32950664, committed:54525952, max:3715249152
Non-Heap Memory Usage: init:2555904, used:49171920, committed:51773440, max:-1
$ jvm com.example.demo.User
其中,com.example.demo.User表示類名。
輸出:
Class: com.example.demo.User
Loaded Count: 1
Instance Count: 1
Total Count: 1
使用以下命令可以在Java應(yīng)用中進行調(diào)試:
$ jad --source-only com.example.demo.DemoController hello
其中,
com.example.demo.DemoController表示類名,hello表示方法名。
輸出:
$ jad --source-only com.example.demo.DemoController hello
Decompiled code of com.example.demo.DemoController#hello is as follows:
$ jdb -attach 127.0.0.1:8000
除了以上介紹的命令之外,Arthas還提供了一些其他有用的命令,例如:
$ sc com.example.demo.DemoController
其中,
com.example.demo.DemoController表示類名。
輸出:
Class: com.example.demo.DemoController
ClassLoader: sun.misc.Launcher$AppClassLoader@18b4aac2
Location: 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
$ 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
$ 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)
$ quit
輸出:
Bye! Enjoy the day, enjoy the life~
以上是Arthas的一些常用命令,可以幫助開發(fā)者快速定位和解決Java應(yīng)用中的問題。當(dāng)然,Arthas還有許多其他的功能和命令,這里只是介紹了一部分,感興趣的讀者可以查看官方文檔或者自行探索。

我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流