springboot实现任务调度
2018-03-19 18:00
423 查看
创建springboot工程,并在入口内添加@Scheduleing注解,开启任务调度功能
//开启任务调度 @EnableScheduling @SpringBootApplication public class ScheduleingApplication { public static void main(String[] args) { SpringApplication.run(ScheduleingApplication.class, args); } }
创建定时任务类
@Component public class ScheduleTask { private static final Logger log = LoggerFactory.getLogger(ScheduleTask.class); private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); //一小时 private static final long ONE_HOURS = 60 * 60 * 1000; //一天 private static final long ONE_DAY = 60 * 60 * 1000 *24; //5秒 private static final long FIVE_SECONDS = 5000; @Scheduled(fixedRate = FIVE_SECONDS) public void scheduledTask() { log.info("The time is now {}", dateFormat.format(new Date())); } @Scheduled(fixedRate = ONE_DAY) public void scheduledTask1() { log.info("我是一个每间隔一天执行一次的调度任务"); } @Scheduled(fixedDelay = ONE_HOURS) public void scheduledTask2() { log.info("我是一个每间隔一天执行一次的调度任务"); } }
测试
小结
1.入口内添加@Scheduleing注解。2.在定时方法上加@Scheduled注解。
相关文章推荐
- Spring-boot使用Quartz实现多线程调度任务
- springboot+Quartz实现任务调度的示例代码
- SpringBoot之旅 -- 定时任务两种(Spring Schedule 与 Quartz 整合 )实现
- quartz结合spring轻松实现任务调度
- 使用Spring + quartz实现定时任务调度
- Spring与Quartz的整合实现定时任务调度
- Spring实现自动任务调度-------------task
- SpringBoot 调度任务及常用任务表达式
- Spring与Quartz的整合实现定时任务调度
- Spring实现自动任务调度-------------task
- Spring与Quartz的整合实现定时任务调度(转)
- Spring3.0与Quartz的整合实现定时任务调度
- Spring整合quartz实现任务调度
- Quartz+Spring Boot实现动态管理定时任务
- Spring与Quartz集成配置实现简单定时任务调度
- 【springboot】【任务调度】 自带任务调度和quartz
- Spring与Quartz的整合实现定时任务调度
- springboot整合Quartz实现动态配置定时任务的方法
- spring boot整合quartz实现多个定时任务
- Spring整合Quartz实现定时任务调度