1、配置
@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;
}
}
2、使用
@Component
public class AsyncTask {
@Async("taskExecutor")
public void tesTask(int i){
System.out.println(Thread.currentThread().getName()+"-----"+i);
}
}
标签:springboot,class,60,线程,使用,taskExecutor,ThreadPoolTaskExecutor,public From: https://blog.51cto.com/chengzheng183/6350509