|
@@ -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:不在新线程中执行任务,而是由调用者所在的线程来执行
|