AsyncLogThreadPoolConfig.java 883 B

1234567891011121314151617181920212223242526272829
  1. package com.ruoyi.sim.config;
  2. import org.springframework.context.annotation.Bean;
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.scheduling.annotation.EnableAsync;
  5. import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
  6. import java.util.concurrent.ThreadPoolExecutor;
  7. /**
  8. * 非核心业务的线程池。
  9. */
  10. @Configuration
  11. @EnableAsync
  12. public class AsyncLogThreadPoolConfig {
  13. @Bean(name = "tp-log")
  14. public ThreadPoolTaskExecutor executor() {
  15. ThreadPoolTaskExecutor e = new ThreadPoolTaskExecutor();
  16. e.setCorePoolSize(10);
  17. e.setMaxPoolSize(100);
  18. e.setQueueCapacity(50);
  19. e.setKeepAliveSeconds(200);
  20. e.setThreadNamePrefix("tp-log-");
  21. e.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
  22. e.initialize();
  23. return e;
  24. }
  25. }