当前位置:网站首页>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);
}边栏推荐
- Lvgl usage experience
- Vs 2019 installation and configuration opencv
- Nanning water leakage detection: warmly congratulate Guangxi Zhongshui on winning the first famous brand in Guangxi
- Ansible简介【暂未完成(半成品)】
- 文件重命名
- Ansible introduction [unfinished (semi-finished products)]
- 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
- Vs 2019 configuration tensorrt
- Nce detail of softmax approximation
- MongoDB簡介
猜你喜欢

VS 2019 配置tensorRT生成engine
![Mongodb replication set [master-slave replication]](/img/2c/8030548455f45fa252062dd90e7b8b.png)
Mongodb replication set [master-slave replication]

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

用Three.js做一个简单的3D场景

900w+ data, from 17s to 300ms, how to operate

Download and install node, NPM and yarn

别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!

MySql实战45讲【事务隔离】

900W+ 数据,从 17s 到 300ms,如何操作

Hi3536C V100R001C02SPC040 交叉编译器安装
随机推荐
MySQL practice 45 [SQL query and update execution process]
MySQL practice 45 lecture [transaction isolation]
FileZilla client download and installation
MySQL Real combat 45 [SQL query and Update Execution Process]
Hi3536C V100R001C02SPC040 交叉编译器安装
QQ小程序开发之 一些前期准备:预约开发账号、下载安装开发者工具、创建qq小程序
Summary of matrix knowledge points in Chapter 2 of Linear Algebra (Jeff's self perception)
Pytorch配置
Captura下载安装及在Captura配置FFmpeg
3D drawing example
Vs 2019 configuration tensorrt
VS克隆时显示403错误
[pyg] understand the messagepassing process, GCN demo details
Advanced redis applications [password protection, data persistence, master-slave synchronization, sentinel mode, transactions] [not completed yet (semi-finished products)]
用Three.js做一個簡單的3D場景
Anhui University | small target tracking: large-scale data sets and baselines
PHP generates PDF tcpdf
navicat 导出数据库的表结构
The idea cannot be loaded, and the market solution can be applied (pro test)
[AI practice] Application xgboost Xgbregressor builds air quality prediction model (I)