LingxinMeng 2 years ago
parent
commit
98998a3c24

+ 1 - 1
simulation-oauth-client/src/main/java/com/css/simulation/oauth/client/controller/advice/AllExceptionHandlerAdvice.java → simulation-oauth-client/src/main/java/com/css/simulation/oauth/client/configuration/advice/AllExceptionHandlerAdvice.java

@@ -1,4 +1,4 @@
-package com.css.simulation.oauth.client.controller.advice;
+package com.css.simulation.oauth.client.configuration.advice;
 
 import api.common.pojo.common.ResponseBodyVO;
 import lombok.extern.slf4j.Slf4j;

+ 11 - 14
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/configuration/async/AsyncConfiguration.java → simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/configuration/pool/PoolConfiguration.java

@@ -1,4 +1,4 @@
-package com.css.simulation.resource.scheduler.configuration.async;
+package com.css.simulation.resource.scheduler.configuration.pool;
 
 import lombok.Data;
 import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -12,23 +12,20 @@ import java.util.concurrent.ThreadPoolExecutor;
 @Data
 @EnableAsync
 @Configuration
-@ConfigurationProperties(prefix = "thread-pool")
-public class AsyncConfiguration {
-    private String threadNamePrefix;    // 名称前缀
-    private int corePoolSize;   // 核心线程数
-    private int maxPoolSize;    // 最大线程数
-    private int queueCapacity;  // 队列大小
+@ConfigurationProperties(prefix = "pool")
+public class PoolConfiguration {
 
+    private PoolParam pool1;
     /**
-     * 在方法上使用 @Async("pool-default")
+     * 在方法上使用 @Async("线程池名称")
      */
-    @Bean(name = "pool-default")
-    public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
+    @Bean(name = "pool1")
+    public ThreadPoolTaskExecutor pool1() {
         ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
-        threadPoolTaskExecutor.setThreadNamePrefix(threadNamePrefix);
-        threadPoolTaskExecutor.setCorePoolSize(corePoolSize);
-        threadPoolTaskExecutor.setMaxPoolSize(maxPoolSize);
-        threadPoolTaskExecutor.setQueueCapacity(queueCapacity);
+        threadPoolTaskExecutor.setThreadNamePrefix(pool1.getThreadNamePrefix());
+        threadPoolTaskExecutor.setCorePoolSize(pool1.getCorePoolSize());
+        threadPoolTaskExecutor.setMaxPoolSize(pool1.getMaxPoolSize());
+        threadPoolTaskExecutor.setQueueCapacity(pool1.getQueueCapacity());
         threadPoolTaskExecutor.setKeepAliveSeconds(3);
         // rejection-policy:当pool已经达到max size的时候,如何处理新任务
         // CALLER_RUNS:不在新线程中执行任务,而是由调用者所在的线程来执行

+ 11 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/configuration/pool/PoolParam.java

@@ -0,0 +1,11 @@
+package com.css.simulation.resource.scheduler.configuration.pool;
+
+import lombok.Data;
+
+@Data
+public class PoolParam {
+    private String threadNamePrefix;    // 名称前缀
+    private int corePoolSize;   // 核心线程数
+    private int maxPoolSize;    // 最大线程数
+    private int queueCapacity;  // 队列大小
+}

+ 1 - 1
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/TaskService.java

@@ -28,7 +28,7 @@ public class TaskService {
 
     // -------------------------------- Comment --------------------------------
 
-    @Async("pool-default")
+    @Async("pool1")
     public void state(String taskId, String state, String podName) {
         TaskEntity taskEntity = taskMapper.selectById(taskId);
         String projectId = taskEntity.getPId(); // 项目 id