|
@@ -1,13 +1,19 @@
|
|
|
-package com.qmth.sop.common.threadPool;//package com.qmth.themis.business.threadPool;
|
|
|
+package com.qmth.sop.business.threadPool;//package com.qmth.themis.business.threadPool;
|
|
|
|
|
|
+import com.qmth.sop.business.cache.CommonCacheService;
|
|
|
+import com.qmth.sop.business.entity.SysConfig;
|
|
|
import com.qmth.sop.common.contant.SystemConstant;
|
|
|
+import com.qmth.sop.common.enums.ExceptionResultEnum;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.context.annotation.Primary;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
import java.util.concurrent.Executor;
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
@@ -24,8 +30,8 @@ public class MyThreadPool extends ThreadPoolTaskExecutor {
|
|
|
private MyThreadPool threadPoolTaskExecutor = null;
|
|
|
static final int cpuNum = Runtime.getRuntime().availableProcessors();
|
|
|
|
|
|
-// @Resource
|
|
|
-// CommonCacheService commonCacheService;
|
|
|
+ @Resource
|
|
|
+ CommonCacheService commonCacheService;
|
|
|
|
|
|
/**
|
|
|
* 线程池
|
|
@@ -33,18 +39,16 @@ public class MyThreadPool extends ThreadPoolTaskExecutor {
|
|
|
* @return
|
|
|
*/
|
|
|
@Bean
|
|
|
-// @Primary
|
|
|
+ @Primary
|
|
|
public Executor taskThreadPool() {
|
|
|
-// SysConfig sysConfigCustomThreadPoolCoreSize = commonCacheService.addSysConfigCache(SystemConstant.CUSTOM_THREAD_POOL_CORE_SIZE);
|
|
|
-// Optional.ofNullable(sysConfigCustomThreadPoolCoreSize).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置是否自定义线程池大小"));
|
|
|
-// boolean customThreadPoolCoreSize = Boolean.valueOf(sysConfigCustomThreadPoolCoreSize.getConfigValue());
|
|
|
-//
|
|
|
-// SysConfig sysConfigThreadPoolCoreSize = commonCacheService.addSysConfigCache(SystemConstant.THREAD_POOL_CORE_SIZE);
|
|
|
-// Optional.ofNullable(sysConfigThreadPoolCoreSize).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置自定义线程池大小"));
|
|
|
-// Integer threadPoolCoreSize = Integer.valueOf(sysConfigThreadPoolCoreSize.getConfigValue());
|
|
|
+ SysConfig sysConfigCustomThreadPoolCoreSize = commonCacheService.addSysConfigCache(SystemConstant.CUSTOM_THREAD_POOL_CORE_SIZE);
|
|
|
+ Optional.ofNullable(sysConfigCustomThreadPoolCoreSize).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置是否自定义线程池大小"));
|
|
|
+ boolean customThreadPoolCoreSize = Boolean.valueOf(sysConfigCustomThreadPoolCoreSize.getConfigValue());
|
|
|
+
|
|
|
+ SysConfig sysConfigThreadPoolCoreSize = commonCacheService.addSysConfigCache(SystemConstant.THREAD_POOL_CORE_SIZE);
|
|
|
+ Optional.ofNullable(sysConfigThreadPoolCoreSize).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置自定义线程池大小"));
|
|
|
+ Integer threadPoolCoreSize = Integer.valueOf(sysConfigThreadPoolCoreSize.getConfigValue());
|
|
|
|
|
|
- boolean customThreadPoolCoreSize = false;
|
|
|
- Integer threadPoolCoreSize = 1;
|
|
|
if (Objects.isNull(threadPoolTaskExecutor)) {
|
|
|
log.info("cpuNum:{}", cpuNum);
|
|
|
threadPoolTaskExecutor = new MyThreadPool();
|