springboot 执行定时任务
2017-10-16 10:39
609 查看
1.maven<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>2.启动程序@EnableScheduling@SpringBootApplication
public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }3.具体的任务类
@Component @Profile({"test","prod"}) public class ScheduleTask { @Scheduled(cron = "0 10 4 1 * ?") public void doTask() { doSomeThing();
}
}
4@Scheduled详解
@Scheduled(fixedRate = 5000):上一次开始执行时间点之后5秒再执行
@Scheduled(fixedDelay = 5000):上一次执行完毕时间点之后5秒再执行
@Scheduled(initialDelay=1000, fixedRate=5000):第一次延迟1秒后执行,之后按fixedRate的规则每5秒执行一次
@Scheduled(cron="*/5 * * * * *"):通过cron表达式定义规则。从后往前分别是年月日时分秒更多例子:
"0 15 10 * * ? 2005" 2005年的每天早上10:15触发 "0 * 14 * * ?" 每天从下午2点开始到2点59分每分钟一次触发 "0 0/5 14 * * ?" 每天从下午2点开始到2:55分结束每5分钟一次触发 "0 0/5 14,18 * * ?" 每天的下午2点至2:55和6点至6点55分两个时间段内每5分钟一次触发 "0 0-5 14 * * ?" 每天14:00至14:05每分钟一次触发 "0 10,44 14 ? 3 WED" 三月的每周三的14:10和14:44触发 "0 15 10 ? * MON-FRI" 每个周一、周二、周三、周四、周五的10:15触发
plus:
https://sanjay-f.github.io/2015/08/24/Spring%E7%9A%84%E4%B8%A4%E7%A7%8D%E4%BB%BB%E5%8A%A1%E8%B0%83%E5%BA%A6Scheduled%E5%92%8CAsync/
相关文章推荐
- springboot动态配置定时任务2种方式,整合Quartz多线程并发执行多个定时任务配置
- Spring Boot使用方法小札(2):执行定时任务
- spring boot-分布式定时任务中,异步执行时JMS无法重新投递消息
- 详解SpringBoot 创建定时任务(配合数据库动态执行)
- springboot动态配置定时任务2种方式,整合Quartz多线程并发执行多个定时任务配置
- SpringBoot开发详解(十二) -- SpringBoot中执行定时任务
- 使用spring @Scheduled注解执行定时任务、
- 使用spring的@Scheduled注解执行定时任务,启动项目不输出警告
- (五)springboot入门之定时任务
- spring boot 集成quartz 2.0 实现前端动态配置(获取spring上下文)的两种方式,启动数据库中已开启定时任务
- SpringBoot之旅 -- 定时任务两种(Spring Schedule 与 Quartz 整合 )实现
- spring-boot集成定时任务
- Spring Boot 定时任务的使用
- 基于Spring Boot 实现定时任务
- Spring Boot 定时任务实现后台管理动态配置(动态添加修改删除定时任务)
- spring执行定时任务
- springboot整合Quartz实现动态配置定时任务的方法
- Spring Boot 整合定时调度任务Quartz
- spring定时任务,执行多个任务[实例]
- springboot之定时任务