diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/CpuController.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/CpuController.java new file mode 100644 index 0000000..8178ce1 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/CpuController.java @@ -0,0 +1,51 @@ +package com.ningdatech.pmapi.sys.controller; + +import com.ningdatech.log.annotation.WebLog; +import com.ningdatech.pmapi.sys.manage.CpuManage; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +/** + * @Classname CpuController + * @Description + * @Date 2023/10/30 11:06 + * @Author PoffyZhang + */ +@Slf4j +@Validated +@RestController +@RequestMapping("/api/v1/cpu") +@Api(value = "CpuController", tags = "CPU提升和关闭提升") +@RequiredArgsConstructor +public class CpuController { + + private final CpuManage cpuManage; + + @ApiOperation(value = "CPU初始化任务", notes = "CPU初始化任务") + @PostMapping("/start") + @WebLog("CPU初始化任务") + public String start() { + cpuManage.whileTrueTask(); + return "初始化成功"; + } + + @ApiOperation(value = "提升CPU", notes = "提升CPU") + @PostMapping("/high/{cpu}") + @WebLog("提升CPU") + public String high(@PathVariable Integer cpu) { + cpuManage.open(cpu); + return "提高成功"; + } + + @ApiOperation(value = "关闭CPU任务", notes = "关闭CPU任务") + @PostMapping("/close") + @WebLog("关闭CPU任务") + public String close() { + cpuManage.close(); + return "关闭成功"; + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/CpuManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/CpuManage.java new file mode 100644 index 0000000..1b5994c --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/CpuManage.java @@ -0,0 +1,43 @@ +package com.ningdatech.pmapi.sys.manage; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * @Classname CpuManage + * @Description + * @Date 2023/8/7 9:25 + * @Author PoffyZhang + */ +@Component +@AllArgsConstructor +@Slf4j +public class CpuManage { + + private volatile Boolean isOpen = Boolean.FALSE; + + private int[][] matrix = new int[1][1]; + + public void open(int i){ + Double pow = Math.pow(10, i); + matrix = new int[pow.intValue()][pow.intValue()]; + this.isOpen = Boolean.TRUE; + } + + public void close(){ + matrix = new int[1][1]; + this.isOpen = Boolean.FALSE; + } + + public void whileTrueTask(){ + while (isOpen) { + // 这个循环会一直运行,直到程序被停止 + for (int i = 0; i < matrix.length; i++) { + for (int j = 0; j < matrix[i].length; j++) { + matrix[i][j] = i * j; + } + } + } + } +}