cpu高分析方法
1,根据pid,查找占用cpu较高的线程
ps -mp pid -o THREAD,tid,time
2,使用jstack定位线程堆栈信息,精确找到异常代码
查看某进程下占用CPU较高的线程:ps p 替换进程号 -L -o pcpu,pid,tid,time,tname,cmd
ps p 427 -L -o pcpu,pid,tid,time,tname,cmd
将获取的线程号(十进制数)转换成十六进制
printf "%x\n" 1539
结果:603
[app_user@pro-02 logs]$ printf "%x\n" 22786
5902
[app_user@pro--02 logs]$ jstack -l 427| grep 0x5902 -A 10
"http-apr-8050-exec-445" #10136 daemon prio=5 os_prio=0 tid=0x00007fdb7001a800 nid=0x5902 waiting on condition [0x00007fdaf77f6000]
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x0000000683dc6748> (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.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)
at org.apache.tomcat.util.threads.TaskQueue.poll(TaskQueue.java:85)
at org.apache.tomcat.util.threads.TaskQueue.poll(TaskQueue.java:31)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1073)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
本文来自博客园,作者:春江潮水连海平,转载请注明原文链接:https://www.cnblogs.com/alonewaiting/p/15520358.html