소스 검색

新增异步任务线程池配置

codingliang 1 년 전
부모
커밋
c601af279a
1개의 변경된 파일16개의 추가작업 그리고 1개의 파일을 삭제
  1. 16 1
      src/main/java/com/sqx/scheduler/config/ScheduledConfig.java

+ 16 - 1
src/main/java/com/sqx/scheduler/config/ScheduledConfig.java

@@ -1,8 +1,12 @@
 package com.sqx.scheduler.config;
 
 import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.AsyncConfigurer;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.Executor;
 
 /**
  * 调度配置
@@ -14,5 +18,16 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 @EnableAsync
 @EnableScheduling
 @Configuration
-public class ScheduledConfig {
+public class ScheduledConfig implements AsyncConfigurer {
+
+    @Override
+    public Executor getAsyncExecutor() {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setCorePoolSize(10);
+        executor.setMaxPoolSize(20);
+        executor.setQueueCapacity(50);
+        executor.setKeepAliveSeconds(60);
+        executor.initialize();
+        return executor;
+    }
 }