AsyncConfig.java 755 B

1234567891011121314151617181920212223242526272829
  1. package org.springblade.common.utils;
  2. import org.springframework.context.annotation.Bean;
  3. import org.springframework.context.annotation.Configuration;
  4. import java.util.concurrent.*;
  5. @Configuration
  6. public class AsyncConfig {
  7. /**
  8. * cpu 核心数量
  9. */
  10. public static final int cpuNum = 1 ;//Runtime.getRuntime().availableProcessors();
  11. /**
  12. * 线程池配置
  13. * @return
  14. */
  15. @Bean("taskExecutor1")
  16. public ThreadPoolExecutor getAsyncExecutor() {
  17. return new ThreadPoolMonitor(cpuNum
  18. , 15
  19. , 600
  20. , TimeUnit.SECONDS
  21. , new LinkedBlockingQueue<>(2000)
  22. , new ThreadPoolExecutor.DiscardOldestPolicy(), "manager-thread-pool");
  23. }
  24. }