@@ -515,7 +515,7 @@ public class ExpertInfoServiceImpl implements ExpertInfoService { | |||||
List<ExpertTag> saveExpertTagList = buildSaveExpertTagList(userId, expertTagList); | List<ExpertTag> saveExpertTagList = buildSaveExpertTagList(userId, expertTagList); | ||||
saveExpertTagList = saveExpertTagList.stream() | saveExpertTagList = saveExpertTagList.stream() | ||||
.filter(r -> ExpertTagEnum.EXPERT_SOURCE.getKey().equals(r.getExpertInfoField())) | |||||
// .filter(r -> ExpertTagEnum.EXPERT_SOURCE.getKey().equals(r.getExpertInfoField())) | |||||
.collect(Collectors.toList()); | .collect(Collectors.toList()); | ||||
if (CollUtil.isNotEmpty(saveExpertTagList)) { | if (CollUtil.isNotEmpty(saveExpertTagList)) { | ||||
iExpertTagService.saveBatch(saveExpertTagList); | iExpertTagService.saveBatch(saveExpertTagList); | ||||
@@ -25,25 +25,17 @@ public class CpuController { | |||||
private final CpuManage cpuManage; | 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 "提高成功"; | return "提高成功"; | ||||
} | } | ||||
@ApiOperation(value = "关闭提升内存", notes = "关闭提升内存") | |||||
@PostMapping("/m-close") | |||||
@WebLog("关闭提升内存") | |||||
@ApiOperation(value = "关闭提升cpu", notes = "关闭提升cpu") | |||||
@PostMapping("/close") | |||||
@WebLog("关闭提升cpu") | |||||
public String close() { | public String close() { | ||||
cpuManage.close(); | cpuManage.close(); | ||||
return "关闭成功"; | return "关闭成功"; | ||||
@@ -3,10 +3,7 @@ package com.ningdatech.pmapi.sys.manage; | |||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.springframework.stereotype.Component; | 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 | * @Classname CpuManage | ||||
@@ -17,56 +14,33 @@ import java.util.concurrent.TimeUnit; | |||||
@Component | @Component | ||||
@Slf4j | @Slf4j | ||||
public class CpuManage { | 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()); | |||||
} | |||||
} | } | ||||
} | } |
@@ -6,13 +6,18 @@ import java.util.concurrent.Executors; | |||||
public class CPUTest { | public class CPUTest { | ||||
public static ExecutorService executorService = Executors.newFixedThreadPool(10); | public static ExecutorService executorService = Executors.newFixedThreadPool(10); | ||||
public static volatile boolean flag = true; | |||||
public static void main(String[] args) { | public static void main(String[] args) { | ||||
for(int i = 0;i < 10;i++){ | for(int i = 0;i < 10;i++){ | ||||
executorService.execute(() -> { | executorService.execute(() -> { | ||||
while (true) { | |||||
while (flag) { | |||||
// 一个复杂的计算任务 | // 一个复杂的计算任务 | ||||
long x = 123456789123456789L; | long x = 123456789123456789L; | ||||
for (int j = 0; j < 10000; j++) { | for (int j = 0; j < 10000; j++) { | ||||
if(!flag){ | |||||
break; | |||||
} | |||||
x = (x * 123456789123456789L) % 123456789; | x = (x * 123456789123456789L) % 123456789; | ||||
} | } | ||||
} | } | ||||
@@ -22,6 +27,7 @@ public class CPUTest { | |||||
try{ | try{ | ||||
Thread.sleep(10000); | Thread.sleep(10000); | ||||
executorService.shutdownNow(); | executorService.shutdownNow(); | ||||
flag = false; | |||||
}catch (Exception e){ | }catch (Exception e){ | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||