当前位置:网站首页>Hutool动态添加定时任务
Hutool动态添加定时任务
2022-07-03 03:27:00 【今朝花落悲颜色】
引入hutool
<dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.6.5</version> </dependency>
在启动类中(springboot项目)增加如下代码:
//支持秒级别定时任务
CronUtil.setMatchSecond(true);
//定时服务启动
CronUtil.start();
触发后后台执行逻辑
//启动定时任务 @GetMapping("/start") public String start() { //动态新增定时任务,因为项目启动时已启动定时服务,所以新增后cron条件触发即执行 String jobId = CronUtil.schedule("0/1 * * * * ? ", new Task() { @Override public void execute() { System.out.println("定时任务执行"); } }); if (!StringUtils.isEmpty(jobId)) { return jobId; } else { return null; } } //停止对应定时任务 @GetMapping("/stop/{jobid}") public void stop(@PathVariable("jobid")String jobid) { CronUtil.remove(jobid); }
边栏推荐
- The calculation of stripe, kernel and padding in CNN
- MySQL practice 45 lecture [transaction isolation]
- Captura下载安装及在Captura配置FFmpeg
- 机械臂速成小指南(八):运动学建模(标准DH法)
- PAT乙级常用函数用法总结
- navicat 导出数据库的表结构
- 静态网页 和 动态网页的区别 & WEB1.0和WEB2.0的区别 & GET 和 POST 的区别
- Spark on yarn resource optimization ideas notes
- User value is the last word in the competition of mobile phone market
- Hi3536c v100r001c02spc040 cross compiler installation
猜你喜欢
Pytoch lightweight visualization tool wandb (local)
idea 加载不了应用市场解决办法(亲测)
[MySQL] the difference between left join, right join and join
Téléchargement et installation du client Filezilla
Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence
The calculation of stripe, kernel and padding in CNN
Pytorch轻量级可视化工具wandb(local)
为什么线程崩溃不会导致 JVM 崩溃
MySql實戰45講【SQL查詢和更新執行流程】
Section 26 detailed explanation and demonstration of IPSec virtual private network configuration experiment - simulation experiment based on packettracer8.0
随机推荐
Download and install node, NPM and yarn
Section 26 detailed explanation and demonstration of IPSec virtual private network configuration experiment - simulation experiment based on packettracer8.0
Limit of one question per day
Anhui University | small target tracking: large-scale data sets and baselines
Node start server
900w+ data, from 17s to 300ms, how to operate
[mathematical logic] propositions and connectives (propositions | propositional symbolization | truth connectives | no | conjunction | disjunction | non truth connectives | implication | equivalence)
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 05 data input and output
labelimg生成的xml文件转换为voc格式
MySQL practice 45 lecture [transaction isolation]
@Accessors注解作用指定前缀遵守驼峰命名
File rename
Limit of one question per day
Don't use the new Dede collection without the updated Dede plug-in
Pytorch配置
el-tree搜索方法使用
监听对象中值变化及访问
Advanced redis applications [password protection, data persistence, master-slave synchronization, sentinel mode, transactions] [not completed yet (semi-finished products)]
Summary of determinant knowledge points in Chapter 1 of Linear Algebra (Jeff's self perception)
Idea set method call ignore case