1、
us过高,应用占用CPU资源过高,需找出具体占用CPU的线程所执行的代码,分析定位问题原因。
分析步骤如下:
![24120212_vDQo.jpg](http://static.oschina.net/uploads/img/201509/24120212_vDQo.jpg)
(2) 找出占用cpu最高的线程
top -Hp 1781
top -Hp 1781
![24120212_mtq9.jpg](http://static.oschina.net/uploads/img/201509/24120212_mtq9.jpg)
(3) 占CPU最高线程17596换算成16进制对应线程44bc
用命令
printf "%x\n" 17596
用命令
printf "%x\n" 17596
![24120212_vX05.jpg](http://static.oschina.net/uploads/img/201509/24120212_vX05.jpg)
(4) 打印占CPU最高JAVA进程1781的堆栈信息
jstack 1781> stackdump.txt
jstack 1781> stackdump.txt
![24120213_uouR.jpg](http://static.oschina.net/uploads/img/201509/24120213_uouR.jpg)
代码如下:
public class CPUConsumeTest {
public static void main(String[] args) {
int count = Runtime.getRuntime().availableProcessors();
System.out.println("processors " + count);
for(int i=0; i<count; i++) {
new Thread(new ConsumeCPUTest()).start();
}
for(int i=0; i<100; i++) {
new Thread(new NotConsumeCPUTest()).start();
}
}
}
class ConsumeCPUTest implements Runnable {
public void run() {
while(true) {
for(int i=0; i<10000000; i++) {
long l = 1000000;
Math.acos(l);
}
try {
Thread.currentThread().sleep(20);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}
class NotConsumeCPUTest implements Runnable {
public void run() {
while(true) {
try {
Thread.currentThread().sleep(50);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}
2、sy过高,上下文切换过频繁,将线程栈打印出来,看是否有哪个锁竞争过于激烈