內(nèi)容源于工作中的總結(jié)和網(wǎng)絡(luò)搜索飘痛。
- 命令找到j(luò)ava線程pid:jps勃教,下面pid是6
root@5pcng:/# jps
6 jar
889 Jps
- 命令查看pid進(jìn)程下的線程: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.查看線程詳細(xì)信息: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
指標(biāo)說明
S0 : 新生代中Survivor space 0區(qū)已使用空間的百分比
S1: 新生代中Survivor space 1區(qū)已使用空間的百分比
E: 新生代已使用空間的百分比
O: 老年代已使用空間的百分比
M: 元數(shù)據(jù)區(qū)使用比例
CCS:壓縮使用比例
YGC: 從應(yīng)用程序啟動(dòng)到當(dāng)前佛南,發(fā)生Yang GC 的次數(shù)
YGCT: 從應(yīng)用程序啟動(dòng)到當(dāng)前武鲁,Yang GC所用的時(shí)間【單位秒】
FGC: 從應(yīng)用程序啟動(dòng)到當(dāng)前,發(fā)生Full GC的次數(shù)
FGCT: 從應(yīng)用程序啟動(dòng)到當(dāng)前头滔,F(xiàn)ull GC所用的時(shí)間
GCT: 從應(yīng)用程序啟動(dòng)到當(dāng)前怖亭,用于垃圾回收的總時(shí)間【單位秒】
jstat 選項(xiàng)
class:類加載統(tǒng)計(jì)(Displays statistics about the behavior of the class loader.)
compiler:編譯統(tǒng)計(jì)(Displays statistics about the behavior of the Java HotSpot VM Just-in-Time compiler.)
gc:垃圾回收統(tǒng)計(jì)(Displays statistics about the behavior of the garbage collected heap.)
gccapacity:堆內(nèi)存統(tǒng)計(jì)(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)計(jì)(Displays statistics of the behavior of the new generation.)
gcnewcapacity:新生代內(nèi)存統(tǒng)計(jì)(Displays statistics about the sizes of the new generations and its corresponding spaces.)
gcold:老年代垃圾回收統(tǒng)計(jì)(Displays statistics about the behavior of the old generation and metaspace statistics.)
gcoldcapacity:老年代內(nèi)存統(tǒng)計(jì)(Displays statistics about the sizes of the old generation.)
gcmetacapacity:元數(shù)據(jù)空間統(tǒng)計(jì)(Displays statistics about the sizes of the metaspace.)
gcutil:總結(jié)垃圾回收統(tǒng)計(jì)(Displays a summary about garbage collection statistics.)
printcompilation:JVM編譯方法統(tǒng)計(jì)(Displays Java HotSpot VM compilation method statistics.)
gccause (推薦使用)
gcutil擁有的輸出列g(shù)ccause也都擁有,還額外多了最后一次GC原因和當(dāng)前GC原因拙毫。
指標(biāo)說明:
LGCC:最后一次GC原因(Cause of last garbage collection)
GCC:當(dāng)前GC原因(Cause of current garbage collection)