CPU飙高测试

public class HighCpuLoad {

    public static void main(String[] args) {
        final int numThreads = 10; // 要使用的线程数

        for (int i = 0; i < numThreads; i++) {
            Thread thread = new Thread(new CpuIntensiveTask());
            thread.start();
        }
    }

    static class CpuIntensiveTask implements Runnable {
        @Override
        public void run() {
            while (true) {
                // 进行一些密集计算操作
                double result = 0;
                for (int i = 0; i < 1000000; i++) {
                    result += Math.sqrt(i) * Math.pow(i, 2) / Math.log(i + 1);
                }
            }
        }
    }
}

CPU飙高测试_第1张图片

你可能感兴趣的:(java,开发语言)