当前位置:网站首页>Quartz(定时器)
Quartz(定时器)
2022-06-27 09:24:00 【Sparkle_wsl】
Quartz(定时器)
使用步骤
导包
<!--定时清理jar包--> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> </dependency> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz-jobs</artifactId> </dependency>自定义一个Job(定时指定的任务)
public class ClearImg { @Autowired private JedisPool jedisPool; public void clearImg(){ System.out.println(jedisPool); //将全部的内容 Set<String> set = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES); if(set!=null){ //调用删除方法 for (String s : set) { QiniuUtils.deleteFileFromQiniu(s); //清除redis中的垃圾图片 jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,s); } } } }配饰Spring-jobs的配置文件
将自定的job配置到Spring中
<!-- 注册自定义Job --> <bean id="jobDemo" class="com.itheima.jobs.ClearImg"></bean>注册JobDetail,作用负责通过反射调用指定的job
<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!-- 注入目标对象 --> <property name="targetObject" ref="jobDemo"/> <!-- 注入目标方法 --> <property name="targetMethod" value="clearImg"/> </bean>注册一个触发器,指定任务触发的时间
<bean id="myTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <!-- 注入JobDetail 也就是执行谁 --> <property name="jobDetail" ref="jobDetail"/> <!-- 指定触发的时间,基于Cron表达式 指定多久执行一次 --> <property name="cronExpression"> <value>0 0 0/1 * * ? </value> </property> </bean>注册一个统一的调度工厂,通过这个调度工厂调度任务
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <!-- 注入多个触发器 --> <property name="triggers"> <list> <!-- 触发器1 --> <ref bean="myTrigger"/> <!-- 触发器2 --> <res bean="xXX"> <!-- .... --> </list> </property> </bean>
Cron表达式
一共有7位,常用的又6位
从做到右:秒 分 时 日 周 年
在线生成Cron表达式
边栏推荐
- Static code block vs construction code block
- One week's experience of using Obsidian (configuration, theme and plug-in)
- MySQL proficient-01 addition, deletion and modification
- June 26, 2022 (LC 6100 counts the number of ways to place houses)
- 隐私计算FATE-离线预测
- Quelques exercices sur les arbres binaires
- HiTek电源维修X光机高压发生器维修XR150-603-02
- 不容置疑,这是一个绝对精心制作的项目
- 内部类~锁~访问修饰符
- Summary of three basic interview questions
猜你喜欢

Advanced mathematics Chapter 7 differential equations

MATLAB小技巧(18)矩阵分析--熵权法

Obsidian 一周使用心得(配置、主题和插件)

最全H桥电机驱动模块L298N原理及应用

Take you to play with the camera module

Imx8qxp DMA resources and usage (unfinished)

ucore lab5

浏览器的markdown插件显示不了图片

DV scroll board width of datav rotation table component

Markem imaje马肯依玛士喷码机维修9450E打码机维修
随机推荐
多个类的设计
有关二叉树的一些练习题
The markdown plug-in of the browser cannot display the picture
[cloud native] 2.3 kubernetes core practice (Part 1)
Understand neural network structure and optimization methods
Reading and writing Apache poi
[diffusion model]
ucore lab3
支付宝微信支付业务流程图
Tips for using Jupiter notebook
E+h secondary meter repair pH transmitter secondary display repair cpm253-mr0005
About the problem that the El date picker Click to clear the parameter and make it null
ThreadLocal再次挖掘它的知识点
Apache POI的读写
1098 insertion or heap sort (PAT class a)
隐私计算FATE-离线预测
了解神经网络结构和优化方法
Preliminary understanding of pytorch
Privacy computing fat offline prediction
DV scroll board width of datav rotation table component