JvmTop.java - jvmtop是一款类似Linux下TOP的Java监控命令,可以时刻查询JVM内部线程运行情况,和Jstack一起配合使用,能够发现导致系统负载增大的一些原因。
jvmtop.sh -h 可以获得帮助.
jvmtop.sh JVM的PID 能够获得这个JVM内部的线程情况。
JVM的PID可以通过PS命令获得。
举例监控sh命令:
#!/bin/sh
PID=`ps aux | sort -rnk 3 | awk '{print $2}' |head -n 1`
/home/jdon/jvmtop.sh -n3 $PID >>out.txt
如果JVM成为最忙碌的,打印出该JVM内部线程,遍历三次,如下:
PID 24188: com.jvmtop.JvmTop
ARGS: 1801
VMARGS:
VM: Sun Microsystems Inc. Java HotSpot(TM) Client VM 1.6.0_31
UP: 0: 3m #THR: 12 #THRPEAK: 12 #THRCREATED: 12 USER: root
GC-Time: 0: 0m #GC-Runs: 67 #TotalLoadedClasses: 1475
CPU: 2.78% GC: 0.00% HEAP: 5m / 245m NONHEAP: 18m / 118m
TID NAME STATE CPU TOTALCPU BLOCKEDBY
14 RMI TCP Connection(1)-10.241.8 RUNNABLE 0.93% 0.77%
1 main TIMED_WAITING 0.93% 86.63%
15 JMX server connection timeout TIMED_WAITING 0.00% 0.00%
13 RMI TCP Accept-0 RUNNABLE 0.00% 0.00%
12 Attach Listener RUNNABLE 0.00% 0.51%
11 Thread-1 TIMED_WAITING 0.00% 0.00%
10 RMI Scheduler(0) TIMED_WAITING 0.00% 0.00%
9 GC Daemon TIMED_WAITING 0.00% 0.00%
8 RMI RenewClean-[110.76.43.83:3 TIMED_WAITING 0.00% 0.00%
4 Signal Dispatcher RUNNABLE 0.00% 0.00%
Note: Only top 10 threads (according cpu load) are shown!