public class cpu
{
public static void main(String[] args)
{
long startTime = 0;// 开始时间
int busyTime = Integer.parseInt(args[0]);// 繁忙时间
int idleTime = Integer.parseInt(args[1]);// 空闲时间
while (true)
{
startTime = System.currentTimeMillis(); // CPU繁忙
while (System.currentTimeMillis() - startTime <= busyTime); // CPU空闲
try
{
Thread.sleep(idleTime);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
java 实现占用特定百分比的CPU资源
最新推荐文章于 2024-07-27 21:26:53 发布