通過java命令查看線程信息

內(nèi)容源于工作中的總結和網(wǎng)絡搜索。

  1. 命令找到java線程pid:jps,下面pid是6
root@5pcng:/# jps
6 jar
889 Jps
  1. 命令查看pid進程下的線程:ps -T -p pid
root@5pcng:/# ps -T -p 6
  PID  SPID TTY          TIME CMD
    6     6 ?        00:00:00 java
    6    37 ?        00:00:00 Service Thread
    6    38 ?        00:00:26 VM Periodic Tas
    6    40 ?        00:00:00 logback-1
    6    42 ?        00:00:01 mysql-cj-abando
    6    47 ?        00:00:01 redisson-netty-
    6    80 ?        00:00:03 quartzScheduler
    6   112 ?        00:00:00 MyHikariCP hous
    6   254 ?        00:00:02 pool-3-thread-1
    6   292 ?        00:00:02 pool-3-thread-2
    6   299 ?        00:00:01 pool-3-thread-3
    6   316 ?        00:00:01 pool-3-thread-4
    6   323 ?        00:00:01 pool-3-thread-5
    6   330 ?        00:00:01 pool-3-thread-6
    6   347 ?        00:00:01 pool-3-thread-7
    6   354 ?        00:00:00 pool-3-thread-8
    6   361 ?        00:00:01 pool-3-thread-9

只查看線程數(shù)可用:ps -T -p ${pid}| wc -l

root@5pcng:/# ps -T -p 6| wc -l
124

3.查看線程詳細信息:jstack -l pid

root@5pcng:/# jstack -l 6
"C1 CompilerThread8" #13 daemon prio=9 os_prio=0 tid=0x00007fd90c2d0000 nid=0x21 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread7" #12 daemon prio=9 os_prio=0 tid=0x00007fd90c2ce000 nid=0x20 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread6" #11 daemon prio=9 os_prio=0 tid=0x00007fd90c2cc000 nid=0x1f waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread5" #10 daemon prio=9 os_prio=0 tid=0x00007fd90c2c9800 nid=0x1e waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread4" #9 daemon prio=9 os_prio=0 tid=0x00007fd90c2c7800 nid=0x1d waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread3" #8 daemon prio=9 os_prio=0 tid=0x00007fd90c2bd800 nid=0x1c waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
"VM Periodic Task Thread" os_prio=0 tid=0x00007fd90c2ee800 nid=0x26 waiting on condition 

JNI global references: 1955

4.查看jvm內(nèi)存占用及垃圾回收情況:jstat -gcutil pid intervalTime(ms)

root@5pcng:/# jstat -gcutil 6 3000
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT   
  0.00  99.01  16.04   8.97  94.88      -     15    0.334     3    0.279    0.613
  0.00  99.01  16.04   8.97  94.88      -     15    0.334     3    0.279    0.613
  0.00  99.01  16.04   8.97  94.88      -     15    0.334     3    0.279    0.613
  0.00  99.01  16.04   8.97  94.88      -     15    0.334     3    0.279    0.613

指標說明

S0 : 新生代中Survivor space 0區(qū)已使用空間的百分比
S1: 新生代中Survivor space 1區(qū)已使用空間的百分比
E: 新生代已使用空間的百分比
O: 老年代已使用空間的百分比
M: 元數(shù)據(jù)區(qū)使用比例

CCS:壓縮使用比例
YGC: 從應用程序啟動到當前,發(fā)生Yang GC 的次數(shù)
YGCT: 從應用程序啟動到當前,Yang GC所用的時間【單位秒】
FGC: 從應用程序啟動到當前,發(fā)生Full GC的次數(shù)
FGCT: 從應用程序啟動到當前,F(xiàn)ull GC所用的時間
GCT: 從應用程序啟動到當前,用于垃圾回收的總時間【單位秒】

jstat 選項

class:類加載統(tǒng)計(Displays statistics about the behavior of the class loader.)
compiler:編譯統(tǒng)計(Displays statistics about the behavior of the Java HotSpot VM Just-in-Time compiler.)
gc:垃圾回收統(tǒng)計(Displays statistics about the behavior of the garbage collected heap.)
gccapacity:堆內(nèi)存統(tǒng)計(Displays statistics about the capacities of the generations and their corresponding spaces.
gccause:垃圾回收原因(Displays a summary about garbage collection statistics (same as -gcutil), with the cause of the last and current (when applicable) garbage collection events.)
gcnew:新生代垃圾回收統(tǒng)計(Displays statistics of the behavior of the new generation.)
gcnewcapacity:新生代內(nèi)存統(tǒng)計(Displays statistics about the sizes of the new generations and its corresponding spaces.)
gcold:老年代垃圾回收統(tǒng)計(Displays statistics about the behavior of the old generation and metaspace statistics.)
gcoldcapacity:老年代內(nèi)存統(tǒng)計(Displays statistics about the sizes of the old generation.)
gcmetacapacity:元數(shù)據(jù)空間統(tǒng)計(Displays statistics about the sizes of the metaspace.)
gcutil:總結垃圾回收統(tǒng)計(Displays a summary about garbage collection statistics.)
printcompilation:JVM編譯方法統(tǒng)計(Displays Java HotSpot VM compilation method statistics.)

gccause (推薦使用)
gcutil擁有的輸出列gccause也都擁有,還額外多了最后一次GC原因和當前GC原因。

指標說明:
LGCC:最后一次GC原因(Cause of last garbage collection)
GCC:當前GC原因(Cause of current garbage collection)

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容