当前位置:网站首页>Hutool dynamically adds scheduled tasks
Hutool dynamically adds scheduled tasks
2022-07-03 03:33:00 【Today, the flowers are sad】
introduce hutool
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.6.5</version>
</dependency>In the startup class (springboot project ) Add the following code :
// Second level timing tasks are supported
CronUtil.setMatchSecond(true);
// The scheduled service starts
CronUtil.start();

After triggering, the background execution logic
// Start timing task
@GetMapping("/start")
public String start() {
// Dynamically add scheduled tasks , Because the scheduled service has been started when the project is started , So after adding cron Execute when the condition is triggered
String jobId = CronUtil.schedule("0/1 * * * * ? ", new Task() {
@Override
public void execute() {
System.out.println(" Scheduled task execution ");
}
});
if (!StringUtils.isEmpty(jobId)) {
return jobId;
} else {
return null;
}
}
// Stop the corresponding scheduled task
@GetMapping("/stop/{jobid}")
public void stop(@PathVariable("jobid")String jobid) {
CronUtil.remove(jobid);
}边栏推荐
- C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions
- Hi3536c v100r001c02spc040 cross compiler installation
- Introduction to mongodb
- MongoDB简介
- 为什么线程崩溃不会导致 JVM 崩溃
- Why does thread crash not cause JVM crash
- MongoDB主配置文件
- [mathematical logic] propositions and connectives (propositions | propositional symbolization | truth connectives | no | conjunction | disjunction | non truth connectives | implication | equivalence)
- 将时间戳转为指定格式的时间
- [combinatorics] brief introduction to generating function (definition of generating function | Newton binomial coefficient | commonly used generating function | correlation with constant | correlation
猜你喜欢

Vs 2019 configure tensorrt to generate engine

Pytoch configuration

Numpy warning visibledeprecationwarning: creating an ndarray from ragged needed sequences

Unity3d RPG implementation (medium)

Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf

Vs Code configure virtual environment

VS 2019配置tensorRT

Gavin teacher's perception of transformer live class - rasa project's actual banking financial BOT Intelligent Business Dialogue robot architecture, process and phenomenon decryption through rasa inte

Nce detail of softmax approximation

Mysql Mac版下载安装教程
随机推荐
Download and install node, NPM and yarn
The XML file generated by labelimg is converted to VOC format
[mathematical logic] propositional logic (propositional and connective review | propositional formula | connective priority | truth table satisfiable contradiction tautology)
Téléchargement et installation du client Filezilla
[mathematical logic] normal form (conjunctive normal form | disjunctive normal form | major item | minor item | maximal item | minor item | principal conjunctive normal form | principal disjunctive no
解决高并发下System.currentTimeMillis卡顿
简易版 微信小程序开发之页面跳转、数据绑定、获取用户信息、获取用户位置信息
递归使用和多维数组对象变一维数组对象
Tidal characteristics of the Bohai Sea and the Yellow Sea
MongoDB基本操作【增、删、改、查】
Hi3536C V100R001C02SPC040 交叉编译器安装
User value is the last word in the competition of mobile phone market
Captura下载安装及在Captura配置FFmpeg
Solve high and send system Currenttimemillis Caton
Application of derivative in daily question
Change and access of median value of listening object
[algebraic structure] group (definition of group | basic properties of group | proof method of group | commutative group)
Advanced redis applications [password protection, data persistence, master-slave synchronization, sentinel mode, transactions] [not completed yet (semi-finished products)]
用Three.js做一个简单的3D场景
[Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)