首页 > 代码库 > 一次java Cpu占用过高的排查

一次java Cpu占用过高的排查

某一个项目CPU占用率一直很高,经常在40%-50%之间,最近比较闲,就开始了挂查工作。

1.通过 jstack命令输出进程的堆栈信息

jstack 2788 >C:\log.txt

将堆栈信息输出到log.txt

"dubbo-remoting-client-heartbeat-thread-1" #46 daemon prio=5 os_prio=0 tid=0x000000005c53e000 nid=0x240c waiting on condition [0x000000006447f000]   java.lang.Thread.State: WAITING (parking)    at sun.misc.Unsafe.park(Native Method)    - parking to wait for  <0x00000000e17fc110> (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.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1088)    at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)    at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)    at java.lang.Thread.run(Thread.java:745)   Locked ownable synchronizers:    - None"Hashed wheel timer #1" #41 prio=5 os_prio=0 tid=0x000000005c53c800 nid=0x271c runnable [0x0000000063fae000]   java.lang.Thread.State: RUNNABLE    at java.lang.Thread.sleep(Native Method)    at org.jboss.netty.util.HashedWheelTimer$Worker.waitForNextTick(HashedWheelTimer.java:504)    at org.jboss.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:402)    at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)    at java.lang.Thread.run(Thread.java:745)   Locked ownable synchronizers:    - None"DubboClientReconnectTimer-thread-1" #44 daemon prio=5 os_prio=0 tid=0x0000000059883800 nid=0x2700 waiting on condition [0x000000006362f000]   java.lang.Thread.State: TIMED_WAITING (parking)    at sun.misc.Unsafe.park(Native Method)    - parking to wait for  <0x00000000e1825be0> (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.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)    at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)    at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)    at java.lang.Thread.run(Thread.java:745)

2. 通过ProcessExplorer查找CPU占用过高的线程

技术分享

从图中可以看到,占用CPU过高的线程ID是8924,再将8924转换为16进行,在刚刚输出的log.txt中查询对应的堆栈信息。

之后再查询相应的代码。CPU过高一般都是有列循环了。

一次java Cpu占用过高的排查