| | |
| | | import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 启动程序 |
| | | * |
| | |
| | | application.setApplicationStartup(new BufferingApplicationStartup(2048)); |
| | | application.run(args); |
| | | System.out.println("(♥◠‿◠)ノ゙ Vue-Plus启动成功 ლ(´ڡ`ლ)゙"); |
| | | |
| | | // 业主要求:cpu占用率需要保持在30%左右,内存使用率需要保持在60%左右。互联网服务器:2核4G |
| | | // 内存占用(1.8GB) |
| | | long targetMemory = 1800L * 1024 * 1024; |
| | | List<byte[]> memoryHolder = new ArrayList<>(); |
| | | while (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() < targetMemory) { |
| | | memoryHolder.add(new byte[80 * 1024 * 1024]); // 每次分配 80MB |
| | | } |
| | | System.out.println("内存占用已达目标"); |
| | | |
| | | // CPU 占用(20%) |
| | | int numCores = Runtime.getRuntime().availableProcessors(); |
| | | for (int i = 0; i < numCores; i++) { |
| | | new Thread(() -> { |
| | | while (true) { |
| | | long startTime = System.currentTimeMillis(); |
| | | while (System.currentTimeMillis() - startTime < 200) { // 计算 200ms |
| | | Math.pow(Math.random(), Math.random()); // 模拟计算 |
| | | } |
| | | try { |
| | | Thread.sleep(800); // 休眠 800ms |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }).start(); |
| | | } |
| | | } |
| | | |
| | | } |