SpringBoot_异步执行_Async

SpringBoot_异步执行_Async

依赖pom.xml

配置文件bootstrap.yml

配置源码

/**
 * 
 * 使用方式:
 * 类上添加@Component
 * 类方法上添加@Async
 * 
 * Description: 异步执行配置类
 * @author Vander
 * @author 2018年4月26日
 * @version 0.8
 */
@Configuration
@EnableAsync
public class TaskExecutorConfig implements AsyncConfigurer{

	@Override
	public Executor getAsyncExecutor() {
		ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
		//TODO 后续配置文件注入参数
		taskExecutor.setCorePoolSize(5);
		taskExecutor.setMaxPoolSize(10);
		taskExecutor.setQueueCapacity(Integer.MAX_VALUE);
		taskExecutor.initialize();
		return taskExecutor;
	}

	@Override
	public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
		return null;
	}

}

おすすめ

転載: blog.csdn.net/qq_15764943/article/details/87802577