1. 查看占用cpu占用过高进程的pid
使用 top名称查看 这里可以看的出来进程是20943
2. 查看该进程中哪个线程占用大量 CPU
ps -mp 20943 -o THREAD,tid,time | grep $( ps -mp 20943 -o THREAD,tid,time | awk 'NR>2 {print $2}' | sort -nr| head -1 ) | head -1
root 1.0 19 - futex_ - - 20956 00:01:19
3. 将线程ID转换成16进制
printf "%x\n" 20956
51dc
4. 使用 jstack命令,查看线程转储信息
jstack 20943 | grep 51dc -A 10 -B 10
at org.apache.catalina.core.StandardServer.await(StandardServer.java:453)
at org.apache.catalina.startup.Catalina.await(Catalina.java:777)
at org.apache.catalina.startup.Catalina.start(Catalina.java:723)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)
"VM Thread" os_prio=0 tid=0x00007fba7c078800 nid=0x51dc runnable
"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00007fba7c01f800 nid=0x51d4 runnable
"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00007fba7c021000 nid=0x51d5 runnable
"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00007fba7c023000 nid=0x51d6 runnable
"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x00007fba7c024800 nid=0x51d7 runnable
"VM Periodic Task Thread" os_prio=0 tid=0x00007fba7c2a0800 nid=0x5217 waiting on condition
#假如有问题可以从这里面信息查看问题