1. @Bean
    2. public ThreadPoolTaskExecutor taskExecutor() {
    3. ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    4. executor.setCorePoolSize(2);
    5. executor.setMaxPoolSize(10);
    6. executor.setQueueCapacity(5000);
    7. executor.setKeepAliveSeconds(30);
    8. executor.setThreadNamePrefix("taskExecutor-");
    9. executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    10. executor.setWaitForTasksToCompleteOnShutdown(true);
    11. executor.setAwaitTerminationSeconds(60);
    12. executor.initialize();
    13. return executor;
    14. }