应用服务器服务起来以后占用CPU一直很高,排查方法如下:
1、使用top命令查看使用CPU过高的进程的pid,按“shift+P”键按照cpu从高到低排列,按“shift+M”键按照内存用高到低排列。
2、根据pid定位占用cpu的线程,并按照占用从高到低排列

#此处的pid为15217
$ ps -mp 15254 -o THREAD,tid,time|sort -rn|head -10 
USER     %CPU PRI SCNT WCHAN  USER SYSTEM   TID     TIME
tomcat   99.9   -    - -         -      -     - 05:10:34
tomcat   99.8  19    - -         -      - 15820 05:10:05
tomcat    0.0  19    - poll_s    -      - 15921 00:00:00
tomcat    0.0  19    - poll_s    -      - 15917 00:00:00
tomcat    0.0  19    - poll_s    -      - 15257 00:00:05
tomcat    0.0  19    - futex_    -      - 15922 00:00:00
tomcat    0.0  19    - futex_    -      - 15920 00:00:00
tomcat    0.0  19    - futex_    -      - 15919 00:00:00
tomcat    0.0  19    - futex_    -      - 15918 00:00:00

3、将占用cpu高的线程id转换为16进制格式

printf "%x\n" 15820
3dcc

4、打印线程的堆栈信息

jstack 15254 | grep 3dcc -A 30

"Thread-2" prio=10 tid=0x00007fe7745cc800 nid=0x3dcc runnable [0x00007fe744c4a000]
   java.lang.Thread.State: RUNNABLE
        at com.yueworldframework.core.support.EventHelper$1.run(EventHelper.java:50)
        at java.lang.Thread.run(Thread.java:745)

"GC Daemon" daemon prio=10 tid=0x00007fe774347800 nid=0x3d04 in Object.wait() [0x00007fe7459dd000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x00000000fd7b8530> (a sun.misc.GC$LatencyLock)
        at sun.misc.GC$Daemon.run(GC.java:117)
        - locked <0x00000000fd7b8530> (a sun.misc.GC$LatencyLock)

"Service Thread" daemon prio=10 tid=0x00007fe7740aa000 nid=0x3bdd runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread1" daemon prio=10 tid=0x00007fe7740a7800 nid=0x3bdb waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" daemon prio=10 tid=0x00007fe7740a4800 nid=0x3bd9 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" daemon prio=10 tid=0x00007fe77409a800 nid=0x3bd8 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Finalizer" daemon prio=10 tid=0x00007fe774083800 nid=0x3bb9 in Object.wait() [0x00007fe746dec000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x00000000fd7b0da0> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
        - locked <0x00000000fd7b0da0> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)

根据输出信息定位或将结果发给开发。

Tags标签: cpu,tomcat Tags相关文章如下:

上一篇:Nginx目录浏览功能autoindex设置

下一篇:提取jks证书配置Nginx使其支持https