当前位置:网站首页>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);
}边栏推荐
- 解决高并发下System.currentTimeMillis卡顿
- navicat 导出数据库的表结构
- 机械臂速成小指南(八):运动学建模(标准DH法)
- [combinatorics] brief introduction to generating function (definition of generating function | Newton binomial coefficient | commonly used generating function | correlation with constant | correlation
- Tidal characteristics of the Bohai Sea and the Yellow Sea
- Nce detail of softmax approximation
- VS 2019配置tensorRT
- MongoDB基本操作【增、删、改、查】
- Vs 2019 configuration du moteur de génération de tensorrt
- [algebraic structure] group (definition of group | basic properties of group | proof method of group | commutative group)
猜你喜欢
![C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions](/img/4a/1df03d9f3315debb4c335260ed39f2.jpg)
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions

User value is the last word in the competition of mobile phone market

Spark on yarn资源优化思路笔记

MongoDB复制集【主从复制】

Hi3536c v100r001c02spc040 cross compiler installation

VS 2019配置tensorRT

idea 加载不了应用市场解决办法(亲测)

Pytorch配置

Limit of one question per day

Ansible简介【暂未完成(半成品)】
随机推荐
解决高並發下System.currentTimeMillis卡頓
[algebraic structure] group (definition of group | basic properties of group | proof method of group | commutative group)
为什么线程崩溃不会导致 JVM 崩溃
使用InputFilter限制EditText时踩坑及解决方案
Application of derivative in daily question
com. fasterxml. jackson. databind. Exc.invalidformatexception problem
Summary of matrix knowledge points in Chapter 2 of Linear Algebra (Jeff's self perception)
监听对象中值变化及访问
The XML file generated by labelimg is converted to VOC format
Vs 2019 configure tensorrt to generate engine
ffmpeg下载安装教程及介绍
[leetcode question brushing day 34] 540 Unique element in array, 384 Disrupt array, 202 Happy number, 149 Maximum number of points on a line
基于Qt的yolov5工程
[mathematical logic] propositions and connectives (propositions | propositional symbolization | truth connectives | no | conjunction | disjunction | non truth connectives | implication | equivalence)
Vs 2019 configuration tensorrt
What happens between entering the URL and displaying the page?
float与0比较
Introduction to mongodb
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
Node start server