AsyncConfig.java 900 B

1234567891011121314151617181920212223242526
  1. package cn.seecoder.paas.util;
  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.Executor;
  7. import java.util.concurrent.ThreadPoolExecutor;
  8. @Configuration
  9. @EnableAsync
  10. public class AsyncConfig {
  11. @Bean("asyncExecutor")
  12. public Executor executor() {
  13. ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
  14. executor.setCorePoolSize(10);
  15. executor.setMaxPoolSize(10);
  16. executor.setQueueCapacity(Integer.MAX_VALUE);
  17. executor.setThreadNamePrefix("seecoder-paas-async-");
  18. executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
  19. executor.initialize();
  20. return executor;
  21. }
  22. }