当前位置:网站首页>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表达式
边栏推荐
- Quelques exercices sur les arbres binaires
- ThreadLocal digs its knowledge points again
- Brief introduction to SSL encryption process
- Parameters argc and argv of main()
- Principle and application of the most complete H-bridge motor drive module L298N
- Process 0, process 1, process 2
- Rockermq message sending mode
- 更改pip镜像源
- Chapter 11 signal (I) - concept
- 手把手带你玩摄像头模组
猜你喜欢

win10为任意文件添加右键菜单
为智能设备提供更强安全保护 科学家研发两种新方法

ucore lab5

Hitek power supply maintenance X-ray machine high voltage generator maintenance xr150-603-02

初步认识pytorch

This, constructor, static, and inter call must be understood!

Source insight 工具安装及使用方法

了解神经网络结构和优化方法

The largest rectangle in the bar graph of force buckle 84

ucore lab3
随机推荐
MATLAB小技巧(18)矩阵分析--熵权法
冒牌构造函数???
Imx8qxp DMA resources and usage (unfinished)
Internal class ~ lock ~ access modifier
Demand visual Engineer
如何获取GC(垃圾回收器)的STW(暂停)时间?
Markem Imaje Marken IMAS printer maintenance 9450e printer maintenance
Matlab tips (18) matrix analysis -- entropy weight method
Introduction to websocket protocol
Source insight 工具安装及使用方法
有關二叉樹的一些練習題
The most direct manifestation of memory leak
IMX8QXP DMA资源和使用(未完结)
内部类~锁~访问修饰符
ucore lab4
ucore lab3
了解神经网络结构和优化方法
1098 Insertion or Heap Sort(堆排序解释)(PAT甲级)
Process 0, process 1, process 2
为智能设备提供更强安全保护 科学家研发两种新方法