当前位置:网站首页>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);
}边栏推荐
- 程序员新人上午使用 isXxx 形式定义布尔类型,下午就被劝退?
- ffmpeg之 一张/多张图片合成视频
- 二进制流转换成字节数组
- Change and access of median value of listening object
- MongoDB簡介
- 静态网页 和 动态网页的区别 & WEB1.0和WEB2.0的区别 & GET 和 POST 的区别
- Pytoch configuration
- MySQL practice 45 [global lock and table lock]
- Summary of determinant knowledge points in Chapter 1 of Linear Algebra (Jeff's self perception)
- Find the storage address of the elements in the two-dimensional array
猜你喜欢
![C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 05 data input and output](/img/38/9c460fc58b62609dd02e7c61207ae6.jpg)
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 05 data input and output

VS 2019 配置tensorRT生成engine

Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!

FileZilla Client下载安装

Section 26 detailed explanation and demonstration of IPSec virtual private network configuration experiment - simulation experiment based on packettracer8.0

Why does thread crash not cause JVM crash

为什么线程崩溃不会导致 JVM 崩溃

Mongodb installation & Deployment

Use of El tree search method

Spark on yarn resource optimization ideas notes
随机推荐
Captura下载安装及在Captura配置FFmpeg
【AI实战】应用xgboost.XGBRegressor搭建空气质量预测模型(一)
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
[pyg] understand the messagepassing process, GCN demo details
Nasvit: neural architecture search of efficient visual converter with gradient conflict perception hypernetwork training
900W+ 数据,从 17s 到 300ms,如何操作
Basic operations of mongodb [add, delete, modify, query]
The XML file generated by labelimg is converted to VOC format
VS 2019配置tensorRT
小程序获取用户头像和昵称
程序员新人上午使用 isXxx 形式定义布尔类型,下午就被劝退?
labelimg生成的xml文件转换为voc格式
PHP generates PDF tcpdf
Agile certification (professional scrum Master) simulation exercises
[combinatorics] Application of exponential generating function (multiple set arrangement problem | different balls in different boxes | derivation of exponential generating function of odd / even sequ
Converts a timestamp to a time in the specified format
The idea cannot be loaded, and the market solution can be applied (pro test)
Idea format code idea set shortcut key format code
Yolov5 project based on QT
[algebraic structure] group (definition of group | basic properties of group | proof method of group | commutative group)