日期:2014-05-20 浏览次数:21190 次
public class CPUTest {
public static void main(String[] args) {
int busyTime = 5;
int idleTime = 50;
long startTime = 0;
while (true) {
startTime = System.currentTimeMillis();
// busy loop
while ((System.currentTimeMillis() - startTime) < busyTime){
// do nothing
}
// idle loop
try {
Thread.sleep(idleTime);
} catch (InterruptedException e) {
System.out.println(e);
}
}
}
}