当前位置:网站首页>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);
}边栏推荐
- Elsevier latex submitted the article pdftex def Error: File `thumbnails/cas-email. jpeg‘ not found: using draf
- com. fasterxml. jackson. databind. Exc.invalidformatexception problem
- Bigvision code
- Find the storage address of the elements in the two-dimensional array
- 文件重命名
- Model transformation onnx2engine
- VS code配置虚拟环境
- MySQL practice 45 [global lock and table lock]
- On the adjacency matrix and adjacency table of graph storage
- Use of El tree search method
猜你喜欢

Summary of matrix knowledge points in Chapter 2 of Linear Algebra (Jeff's self perception)

小程序获取用户头像和昵称
![Mongodb replication set [master-slave replication]](/img/2c/8030548455f45fa252062dd90e7b8b.png)
Mongodb replication set [master-slave replication]

Use of El tree search method

Nce detail of softmax approximation

ffmpeg之 一张/多张图片合成视频

numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences

用Three.js做一個簡單的3D場景

softmax的近似之NCE详解

Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
随机推荐
Téléchargement et installation du client Filezilla
Summary of matrix knowledge points in Chapter 2 of Linear Algebra (Jeff's self perception)
Nce detail of softmax approximation
Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence
User value is the last word in the competition of mobile phone market
Latest version of NPM: the "NPM" item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check
The XML file generated by labelimg is converted to VOC format
Hi3536C V100R001C02SPC040 交叉编译器安装
Hi3536c v100r001c02spc040 cross compiler installation
[Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)
Mongodb installation & Deployment
[combinatorics] brief introduction to generating function (definition of generating function | Newton binomial coefficient | commonly used generating function | correlation with constant | correlation
Convert binary stream to byte array
BigVision代码
Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
Vs 2019 configuration du moteur de génération de tensorrt
解决高并发下System.currentTimeMillis卡顿
文件重命名
VS 2019 配置tensorRT生成engine
labelimg生成的xml文件转换为voc格式