燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2023-08-08 436e03fe73a19bd485e23f78da5d851bbfe85d25
src/main/java/com/yssh/config/ThreadPoolConfig.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,46 @@
package com.yssh.config;
import java.util.concurrent.ThreadPoolExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
/**
 * çº¿ç¨‹æ± é…ç½®
 *
 * @author tam
 **/
@Configuration
@EnableAsync
public class ThreadPoolConfig {
   // æ ¸å¿ƒçº¿ç¨‹æ± å¤§å°
   private int corePoolSize = 50;
   // æœ€å¤§å¯åˆ›å»ºçš„线程数
   private int maxPoolSize = 200;
   // é˜Ÿåˆ—最大长度
   private int queueCapacity = 1000;
   // çº¿ç¨‹æ± ç»´æŠ¤çº¿ç¨‹æ‰€å…è®¸çš„空闲时间
   private int keepAliveSeconds = 300;
   //配置线程池中的线程的名称前缀
   private String threadNamePrefix = "async-importDB-";
   @Bean(name = "threadPoolTaskExecutor")
   public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
      ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
      executor.setMaxPoolSize(maxPoolSize);
      executor.setCorePoolSize(corePoolSize);
      executor.setQueueCapacity(queueCapacity);
      executor.setKeepAliveSeconds(keepAliveSeconds);
      executor.setThreadNamePrefix(threadNamePrefix);
      // çº¿ç¨‹æ± å¯¹æ‹’绝任务(无线程可用)的处理策略
      executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
      return executor;
   }
}