发现java程序cpu利用率100%的解决方法

最近发现一个java程序的cpu利用率总是在100%,开始没注意,以为是有负载在正常跑,后来发现不是这么一个情况,应该是程序里的某个线程在死循环中,只是程序里面n多线程,怎么知道是哪个线程把cpu占满了?


1)先用top找出哪个线程占着cpu

shell下面用

[engine@tempt145 /data/itnProduct/ds2]$ top -H -p 8969

结果

top - 17:59:02 up 113 days,  1:37,  2 users,  load average: 0.00, 0.30, 0.66
Tasks:  52 total,   0 running,  52 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.4%us,  0.1%sy,  0.0%ni, 99.4%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  32950552k total, 32318012k used,   632540k free,   249572k buffers
Swap: 34996216k total,  8301540k used, 26694676k free, 10734080k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                                          
 8969 engine    21   0 2544m 363m 9864 S  0.0  1.1   0:00.00 java                                                                                                                              
 8971 engine    25   0 2544m 363m 9864 S  0.0  1.1   0:04.25 java                                                                                                                              
 8972 engine    23   0 2544m 363m 9864 S  0.0  1.1   0:00.00 java                                                                                                                              
 8973 engine    24   0 2544m 363m 9864 S  0.0  1.1   0:00.00 java                                                                                                                              
 8974 engine    19   0 2544m 363m 9864 S  0.0  1.1   0:00.00 java                                                                                                                              
 8975 engine    19   0 2544m 363m 9864 S  0.0  1.1   0:00.00 java                                                                                                                              
 8976 engine    19   0 2544m 363m 9864 S  0.0  1.1   0:00.00 java                                                                                                                              
 8977 engine    19   0 2544m 363m 9864 S  0.0  1.1   0:00.00 java                                                                                                                              
 8978 engine    19   0 2544m 363m 9864 S  0.0  1.1   0:00.00 java    

找到cpu为100%的PID

2)

jsack -F 8969 > cpu_100

然后在cpu_100里面找到刚刚定位的PID,这里面会精确的告诉你是哪行代码让cpu100%了


嗯 到于是什么原因把cpu搞成100%的,下一篇blog在说




你可能感兴趣的:(Java,Java,Concurrency)