排查java cpu飙升问题

top命令 拿到对应的pid 值

Tasks: 221 total,   1 running, 128 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.3 us,  0.7 sy,  0.0 ni, 97.8 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 32937956 total,   238156 free, 31171956 used,  1527844 buff/cache
KiB Swap:        0 total,        0 free,        0 used.  1015128 avail Mem 
  scroll coordinates: y = 1/221 (tasks), x = 1/12 (fields)
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                 
 1422 root      20   0 53.096g 9.056g  98792 S  22.9 28.8 126274:08 java                                                                                    
27309 116       20   0 63.951g 0.010t 772280 S  10.3 32.7 120541:24 java                                                                                    
 1688 root      20   0 50.130g 8.648g  82016 S   3.0 27.5  20943:04 java

ps -mp 1422 -o THREAD,tid,time  #通过pid 信息 1422是进程的id

root@mng-57:~# ps -mp 1422 -o THREAD,tid,time #第一行 是总占用 
USER     %CPU PRI SCNT WCHAN  USER SYSTEM   TID     TIME  #每个线程的 占用情况   最后一列是占用的时长
root     18.5   -    - -         -      -     - 87-16:35:06
root      0.0  19    - futex_    -      -  1422 00:00:00
root      0.0  19    - futex_    -      -  1423 00:00:06
root      0.0  19    - futex_    -      -  1424 00:03:31
root      0.0  19    - futex_    -      -  1425 00:03:31
root      1.4  19    - ep_pol    -      -  1518 6-20:52:05
root      1.6  19    - ep_pol    -      -  1537 7-13:50:47

 

 

root@mng-57:~# printf "%x\n" 1537 #把占用 过高的 线程id 转换成16进制
601
root@mng-57:~# jstack 1422 |grep 601 -A 100 #得到对应的堆栈的详细列表
"SendMessageThread_7" #181 prio=5 os_prio=0 tid=0x00007fc76017fdd0 nid=0x66c waiting on condition [0x00007fc56cd04000]
   java.lang.Thread.State: WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x00000005c0024f00> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
    at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
    at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

"SendMessageThread_4" #180 prio=5 os_prio=0 tid=0x00007fc758004ed0 nid=0x66b waiting on condition [0x00007fc56e978000]
   java.lang.Thread.State: WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x00000005c0024f00> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
    at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
    at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

 

 

posted @ 2022-07-04 16:40  崽崽1573  阅读(221)  评论(0编辑  收藏  举报