spring Boot 中使用线程池异步执行多个定时任务
2019-05-06 10:00
1131 查看
spring Boot 中使用线程池异步执行多个定时任务
在启动类中添加注解@EnableScheduling
第一步添加注解,这样才会使定时任务启动
配置自定义线程池
@Configuration public class ScheduleConfiguration implements SchedulingConfigurer { @Value("${schedule.max-threads:20}") private int coreSize; @Override public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { taskRegistrar.setScheduler(this.getTaskScheduler()); } private ThreadPoolTaskScheduler getTaskScheduler() { ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.setPoolSize(this.coreSize); taskScheduler.setThreadNamePrefix("schedule-pool-"); taskScheduler.afterPropertiesSet(); return taskScheduler; } # 编写定时任务 ```javascript @Scheduled(cron = "0 0/30 * * * ? ")//定时任务的执行时间ian private void updateChapterHotValue() { //自己的定时任务业务逻辑 }
相关文章推荐
- spring boot使用自定义配置的线程池执行Async异步任务
- spring boot使用自定义配置的线程池执行Async异步任务
- springboot使用定时任务、异步
- spring boot使用自定义的线程池执行Async任务
- spring boot-执行Async任务时,使用自定义的线程池
- 深入浅出spring boot 2.x 07-spring异步线程池&消息&定时任务&websocket【笔记】
- springboot中使用定时任务,异步调用,自定义配置参数(八)
- Spring Boot使用方法小札(2):执行定时任务
- spring boot-分布式定时任务中,异步执行时JMS无法重新投递消息
- 使用spring @Scheduled注解执行定时任务
- 使用spring @Scheduled注解执行定时任务、
- 详解Spring Boot中使用@Scheduled创建定时任务
- 使用Spring定时任务并且通过AOP监控任务执行情况
- (14)Spring Boot定时任务的使用【从零开始学Spring Boot】
- (14)Spring Boot定时任务的使用【从零开始学Spring Boot】
- 使用spring @Scheduled注解执行定时任务
- 任务调度5-------Spring中使用timetask执行定时任务
- 14. Spring Boot定时任务的使用【从零开始学Spring Boot】
- Spring Boot中使用@Scheduled创建定时任务
- 使用spring @Scheduled注解执行定时任务