ThreadConfig.java 966 B

123456789101112131415161718192021222324252627282930313233
  1. package com.dgtly.sync.config;
  2. import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.scheduling.annotation.AsyncConfigurer;
  5. import org.springframework.scheduling.annotation.EnableAsync;
  6. import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
  7. import java.util.concurrent.Executor;
  8. @Configuration
  9. @EnableAsync
  10. public class ThreadConfig implements AsyncConfigurer {
  11. @Override
  12. public Executor getAsyncExecutor() {
  13. ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
  14. executor.setCorePoolSize(8);
  15. executor.setMaxPoolSize(1000);
  16. executor.setQueueCapacity(500);
  17. executor.setKeepAliveSeconds(30000);
  18. executor.initialize();
  19. return executor;
  20. }
  21. @Override
  22. public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
  23. return null;
  24. }
  25. }