浏览代码

提升CPU的功能

tags/24080901
PoffyZhang 1年前
父节点
当前提交
c365d81ea4
共有 2 个文件被更改,包括 94 次插入0 次删除
  1. +51
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/CpuController.java
  2. +43
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/CpuManage.java

+ 51
- 0
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 "关闭成功";
}
}

+ 43
- 0
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;
}
}
}
}
}

正在加载...
取消
保存