diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/expert/service/impl/ExpertInfoServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/expert/service/impl/ExpertInfoServiceImpl.java index 3f0b807..d2e8b68 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/expert/service/impl/ExpertInfoServiceImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/expert/service/impl/ExpertInfoServiceImpl.java @@ -515,7 +515,7 @@ public class ExpertInfoServiceImpl implements ExpertInfoService { List saveExpertTagList = buildSaveExpertTagList(userId, expertTagList); saveExpertTagList = saveExpertTagList.stream() - .filter(r -> ExpertTagEnum.EXPERT_SOURCE.getKey().equals(r.getExpertInfoField())) +// .filter(r -> ExpertTagEnum.EXPERT_SOURCE.getKey().equals(r.getExpertInfoField())) .collect(Collectors.toList()); if (CollUtil.isNotEmpty(saveExpertTagList)) { iExpertTagService.saveBatch(saveExpertTagList); 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 index 8311116..68f2cbf 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/CpuController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/CpuController.java @@ -25,25 +25,17 @@ public class CpuController { private final CpuManage cpuManage; - @ApiOperation(value = "内存初始化任务", notes = "内存初始化任务") - @PostMapping("/m-start") - @WebLog("CPU初始化任务") - public String mStart() { - cpuManage.whileTrueTask(); - return "初始化成功"; - } - - @ApiOperation(value = "提升内存", notes = "提升内存") - @PostMapping("/m-high/{num}") - @WebLog("提升内存") - public String high(@PathVariable Integer num) { - cpuManage.open(num); + @ApiOperation(value = "提升cpu 增加一个线程", notes = "提升cpu 增加一个线程") + @PostMapping("/high") + @WebLog("提升cpu") + public String high() { + cpuManage.high(); return "提高成功"; } - @ApiOperation(value = "关闭提升内存", notes = "关闭提升内存") - @PostMapping("/m-close") - @WebLog("关闭提升内存") + @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 index 778c300..add6771 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/CpuManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/CpuManage.java @@ -3,10 +3,7 @@ package com.ningdatech.pmapi.sys.manage; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.LinkedBlockingDeque; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; /** * @Classname CpuManage @@ -17,56 +14,33 @@ import java.util.concurrent.TimeUnit; @Component @Slf4j public class CpuManage { - - private Boolean isOpen = Boolean.FALSE; - - private int[][] matrix = new int[1][1]; - - private static ExecutorService executorService = null; - - private static Integer THREAD_MAX = 10; - - private static Integer THREAD_IDLE = 20; - - private static Integer THREAD_CAPACITY = 30; - -// static { -// executorService = new ThreadPoolExecutor(THREAD_MAX,THREAD_MAX, -// THREAD_IDLE, TimeUnit.SECONDS, -// new LinkedBlockingDeque<>(THREAD_CAPACITY), -// null,null); -// } - - public void open(int i){ - Double pow = Math.pow(10, i); - matrix = new int[pow.intValue()][pow.intValue()]; - this.isOpen = Boolean.TRUE; - whileTrueTask(); - } - - 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; - try{ - Thread.sleep(10); - if(!isOpen){ - break; - } - }catch (InterruptedException e){ - log.error(e.getMessage()); + private static ExecutorService executorService = Executors.newFixedThreadPool(10); + + private static volatile boolean flag = true; + + public void high() { + flag = true; + executorService.execute(() -> { + while (flag) { + // 一个复杂的计算任务 + long x = 123456789123456789L; + for (int j = 0; j < 10000; j++) { + if(!flag){ + break; } + x = (x * 123456789123456789L) % 123456789; } } - } - + }); + } + public void close(){ + try{ + executorService.shutdownNow(); + flag = false; + executorService = Executors.newFixedThreadPool(10); + }catch (Exception e){ + log.error(e.getMessage()); + } } } diff --git a/pmapi/src/test/java/com/ningdatech/pmapi/cpu/CPUTest.java b/pmapi/src/test/java/com/ningdatech/pmapi/cpu/CPUTest.java index c5a991a..48dd2df 100644 --- a/pmapi/src/test/java/com/ningdatech/pmapi/cpu/CPUTest.java +++ b/pmapi/src/test/java/com/ningdatech/pmapi/cpu/CPUTest.java @@ -6,13 +6,18 @@ import java.util.concurrent.Executors; public class CPUTest { public static ExecutorService executorService = Executors.newFixedThreadPool(10); + public static volatile boolean flag = true; + public static void main(String[] args) { for(int i = 0;i < 10;i++){ executorService.execute(() -> { - while (true) { + while (flag) { // 一个复杂的计算任务 long x = 123456789123456789L; for (int j = 0; j < 10000; j++) { + if(!flag){ + break; + } x = (x * 123456789123456789L) % 123456789; } } @@ -22,6 +27,7 @@ public class CPUTest { try{ Thread.sleep(10000); executorService.shutdownNow(); + flag = false; }catch (Exception e){ e.printStackTrace(); }