springboot 执行定时任务
来源:互联网 发布:东风41知乎 编辑:程序博客网 时间:2024/06/18 05:33
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/
阅读全文
0 0
- springboot 执行定时任务
- SpringBoot开发详解(十二) -- SpringBoot中执行定时任务
- SpringBoot定时任务说明
- springboot定时任务
- springboot(九):定时任务
- springboot(九):定时任务
- springboot 定时任务
- SpringBoot-@Schedule定时任务
- SpringBoot定时任务SchedulingTasks
- SpringBoot 定时任务
- SpringBoot 定时任务
- SpringBoot 定时任务
- springboot (7) 定时任务
- SpringBoot定时任务
- SpringBoot (九) :定时任务
- springboot(九):定时任务
- springboot 定时任务
- springboot实现定时任务
- C++内置数组和array的比较
- eclipse tomcat debug不能进入断点
- Executors.newSingleThreadScheduledExecutor();线程池中放入多个线程问题
- HDOJ 1715 大菲波数(大数)
- django添加新的adnim时报错:django Cannot add or update a child row: a foreign key constraint fails (`mxonlin
- springboot 执行定时任务
- IDEA破解 2017 IDEA license server 激活(可用)
- C#读写文件时出现占用的解决办法
- adb操作指令
- 字典树学习与使用
- Spring Boot 集成MyBatis
- makeObjectsPerformSelector 方法的用法
- 用PHP的PDO方法操作MySQL数据库方法(查询 更新 删除)
- 修改数据库密码