Java让cpu的占用率保持一条直线,javacpu,// CPU使用率其实就
分享于 点击 19005 次 点评:103
Java让cpu的占用率保持一条直线,javacpu,// CPU使用率其实就
// CPU使用率其实就是你运行的程序占用的CPU资源,表示你的机器在某个时间点的运行程序的情况。public class CPUTest{ public static void main(String[] args) { long startTime = 0;// 开始时间 int busyTime = 10;// 繁忙时间 int idleTime = 10;// 空闲时间 while (true) { startTime = System.currentTimeMillis(); // CPU繁忙 while (System.currentTimeMillis() - startTime <= busyTime) ; // CPU空闲 try { Thread.sleep(idleTime); } catch (InterruptedException e) { e.printStackTrace(); } } }}
用户点评