|
@@ -0,0 +1,56 @@
|
|
|
|
|
+package cn.seecoder.web.infrastructure.config;
|
|
|
|
|
+
|
|
|
|
|
+import lombok.Data;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.concurrent.Executor;
|
|
|
|
|
+import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 部署流水线异步线程池配置
|
|
|
|
|
+ */
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Data
|
|
|
|
|
+@Configuration
|
|
|
|
|
+@ConfigurationProperties(prefix = "seecoder.deploy.thread-pool")
|
|
|
|
|
+public class DeployAsyncConfig {
|
|
|
|
|
+
|
|
|
|
|
+ public static final String DEPLOY_EXECUTOR = "deployExecutor";
|
|
|
|
|
+
|
|
|
|
|
+ /** 核心线程数 */
|
|
|
|
|
+ private int corePoolSize = 60;
|
|
|
|
|
+ /** 最大线程数 */
|
|
|
|
|
+ private int maxPoolSize = 100;
|
|
|
|
|
+ /** 队列容量 */
|
|
|
|
|
+ private int queueCapacity = 1000;
|
|
|
|
|
+ /** 线程名前缀 */
|
|
|
|
|
+ private String threadNamePrefix = "deploy-pipeline-";
|
|
|
|
|
+ /** 空闲线程存活时间(秒) */
|
|
|
|
|
+ private int keepAliveSeconds = 60;
|
|
|
|
|
+ /** 等待所有任务完成后再关闭线程池 */
|
|
|
|
|
+ private boolean waitForTasksToCompleteOnShutdown = true;
|
|
|
|
|
+ /** 关闭时最长等待时间(秒) */
|
|
|
|
|
+ private int awaitTerminationSeconds = 60;
|
|
|
|
|
+
|
|
|
|
|
+ @Bean(name = DEPLOY_EXECUTOR)
|
|
|
|
|
+ public Executor deployExecutor() {
|
|
|
|
|
+ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
|
|
|
|
+ executor.setCorePoolSize(corePoolSize);
|
|
|
|
|
+ executor.setMaxPoolSize(maxPoolSize);
|
|
|
|
|
+ executor.setQueueCapacity(queueCapacity);
|
|
|
|
|
+ executor.setThreadNamePrefix(threadNamePrefix);
|
|
|
|
|
+ executor.setKeepAliveSeconds(keepAliveSeconds);
|
|
|
|
|
+ executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
|
|
|
|
+ executor.setWaitForTasksToCompleteOnShutdown(waitForTasksToCompleteOnShutdown);
|
|
|
|
|
+ executor.setAwaitTerminationSeconds(awaitTerminationSeconds);
|
|
|
|
|
+ executor.initialize();
|
|
|
|
|
+ log.info("部署线程池初始化完成, 核心线程数: {}, 最大线程数: {}, 队列容量: {}",
|
|
|
|
|
+ corePoolSize, maxPoolSize, queueCapacity);
|
|
|
|
|
+ return executor;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|