排查线程占用cpu高的情况
1.展示机器上所有线程的cpu利用率
ps H -eo user,pid,ppid,tid,time,%cpu,cmd --sort=%cpu
按照cpu从小到大排序
admin 24931 20874 24931 00:00:00 0.0 ps H -eo user,pid,ppid,tid,time,%cpu,cmd --sort=%cpu
admin 25076 1 25076 00:00:31 0.0 /export/servers/autodeploy_agent/bin/deploy -c /export/servers/autodeploy_agent/conf/config.json -s restart > /dev/null 2>&
admin 25076 1 25086 00:00:39 0.0 /export/servers/autodeploy_agent/bin/deploy -c /export/servers/autodeploy_agent/conf/config.json -s restart > /dev/null 2>&
admin 25076 1 25087 00:00:00 0.0 /export/servers/autodeploy_agent/bin/deploy -c /export/servers/autodeploy_agent/conf/config.json -s restart > /dev/null 2>&
admin 25076 1 25088 00:00:43 0.0 /export/servers/autodeploy_agent/bin/deploy -c /export/servers/autodeploy_agent/conf/config.json -s restart > /dev/null 2>&
admin 25076 1 25089 00:00:26 0.0 /export/servers/autodeploy_agent/bin/deploy -c /export/servers/autodeploy_agent/conf/config.json -s restart > /dev/null 2>&
admin 25076 1 25090 00:00:00 0.0 /export/servers/autodeploy_agent/bin/deploy -c /export/servers/autodeploy_agent/conf/config.json -s restart > /dev/null 2>&
admin 25076 1 5881 00:00:44 0.0 /export/servers/autodeploy_agent/bin/deploy -c /export/servers/autodeploy_agent/conf/config.json -s restart > /dev/null 2>&
admin 25076 1 5884 00:00:45 0.0 /export/servers/autodeploy_agent/bin/deploy -c /export/servers/autodeploy_agent/conf/config.json -s restart > /dev/null 2>&
admin 25139 1 25139 00:00:00 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25145 00:00:00 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25149 00:00:00 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25150 00:00:00 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25151 00:00:27 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25152 00:00:00 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25154 00:00:00 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25155 00:00:00 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25156 00:00:10 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25157 00:00:04 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25158 00:00:00 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25159 00:05:37 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25175 00:00:00 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25176 00:00:00 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25177 00:00:23 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25178 00:00:10 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25179 00:00:08 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25180 00:00:03 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25181 00:00:00 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 25182 00:01:08 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 25139 1 24341 00:00:00 0.0 /export/servers/jdk1.6.0_25/bin/java -server -Xms128M -Xmx256M -Xss256K -XX:PermSize=32M -XX:MaxPermSize=32M -XX:+UseAdapti
admin 3231 1 3290 00:05:57 0.1 /export/servers/jdk1.8.0_60/bin/java -Xms2G -Xmx2G -server -XX:MaxPermSize=256M -Xss256K -Dloader.path=file:/export/Instanc
admin 3231 1 3870 00:07:02 0.1 /export/servers/jdk1.8.0_60/bin/java -Xms2G -Xmx2G -server -XX:MaxPermSize=256M -Xss256K -Dloader.path=file:/export/Instanc
admin 3231 1 3889 00:21:52 0.4 /export/servers/jdk1.8.0_60/bin/java -Xms2G -Xmx2G -server -XX:MaxPermSize=256M -Xss256K -Dloader.path=file:/export/Instanc
admin 3231 1 3888 00:22:20 0.5 /export/servers/jdk1.8.0_60/bin/java -Xms2G -Xmx2G -server -XX:MaxPermSize=256M -Xss256K -Dloader.path=file:/export/Instanc
2. 线程id转16进制
3888转16进制为f30
[admin@pod-qidzou9g82 ~]$ printf '%x\n' 3888
f30
3.查看该线程id的栈信息
jstack 3231 | egrep 'f30' -A 10
结果
[admin@pod-qidzou9g82 ~]$ jstack 3231 | egrep 'f30' -A 10
"MP-SystemClock" #61 daemon prio=5 os_prio=0 tid=0x00007f54cc40b000 nid=0xf30 runnable [0x00007f54afbf6000]
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x0000000081748448> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
原创:做时间的朋友