欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java进程CPU过高问题定位

程序员文章站 2022-07-13 09:03:06
...

 

1、top命令查看过高CPU的pid,命令:top

[root@test-v3 bin]# top
top - 16:44:22 up 173 days,  7:05,  2 users,  load average: 0.74, 0.71, 0.61
Tasks: 150 total,   1 running, 149 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.8%us,  0.4%sy,  0.0%ni, 98.1%id,  0.0%wa,  0.0%hi,  0.0%si,  0.7%st
Mem:   8061116k total,  7924856k used,   136260k free,   234996k buffers
Swap:  4194300k total,   383972k used,  3810328k free,  1191756k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                         
  949 root      20   0 3576m 622m 9852 S  3.3  7.9   1194:48 java                                                                             
 5485 root      20   0 3327m 688m 9804 S  3.3  8.8   1769:07 java                                                                             
  980 root      20   0 3460m 692m  10m S  3.0  8.8   1834:53 java                                                                             
 1012 root      20   0 3393m 668m  10m S  3.0  8.5   1824:38 java                                                                             
14017 root      20   0 2841m 393m 9564 S  2.7  5.0   2079:06 java                                                                             
 1042 root      20   0 3522m 725m   9m S  0.7  9.2 366:09.83 java

 

 

2、定位线程,命令:ps -mp pid -o THREAD,tid,time | sort -rn

[root@test-v3 bin]# ps -mp 949 -o THREAD,tid,time | sort -rn
USER     %CPU PRI SCNT WCHAN  USER SYSTEM   TID     TIME
root      3.2  19    - futex_    -      - 31587 13:37:04
root      2.5   -    - -         -      -     - 19:55:11
root      0.1  19    - futex_    -      -  1849 01:14:46

 

 

3、将线程ID转为 16进制格式,命令:printf "%x\n" tid

[root@test-v3 bin]# printf "%x\n" 31587
7b63

 

 

4、打印堆栈信息 ,命令:jstack pid |grep 十六进制格式tid -A 10

其中-A 10表示查找到所在行的后10行。

[root@test-v3 bin]# cd /usr/java/jdk1.7.0_80/bin
[root@test-v3 bin]# ./jstack 949 |grep 7b63 -A 30
"System Clock" daemon prio=10 tid=0x00007f42904b0800 nid=0x7b63 runnable [0x00007f41f6084000]
   java.lang.Thread.State: TIMED_WAITING (parking)
	at sun.misc.Unsafe.park(Native Method)
	- parking to wait for  <0x00000000eca553a8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
	at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2082)
	at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1090)
	at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:807)
	at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)

"http-bio-8084-exec-10" daemon prio=10 tid=0x00007f422c011000 nid=0x210 waiting on condition [0x00007f41f6684000]
   java.lang.Thread.State: WAITING (parking)
	at sun.misc.Unsafe.park(Native Method)
	- parking to wait for  <0x00000000ec542870> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
	at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
	at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
	at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:104)
	at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:32)
	at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

"http-bio-8084-exec-9" daemon prio=10 tid=0x00007f422c00f800 nid=0x7229 waiting on condition [0x00007f41f6785000]
   java.lang.Thread.State: WAITING (parking)
	at sun.misc.Unsafe.park(Native Method)

 

 

相关标签: java