1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| @Configuration @EnableAsync public class TaskPoolConfig {
@Bean("taskExecutor") public Executor taskExecutro(){ ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(10); taskExecutor.setMaxPoolSize(50); taskExecutor.setQueueCapacity(200); taskExecutor.setKeepAliveSeconds(60); taskExecutor.setThreadNamePrefix("taskExecutor--"); taskExecutor.setWaitForTasksToCompleteOnShutdown(true); taskExecutor.setAwaitTerminationSeconds(60); return taskExecutor; } }
|
1 2 3
| @Async("taskExecutor") public void doExecute(){ }
|
注:调起一次就会去连接池中判断是否有线程,有空余线程则执行