当前位置:网站首页>Quartz (timer)
Quartz (timer)
2022-06-27 09:33:00 【Sparkle_ wsl】
Quartz( Timer )
Use steps
Guide pack
<!-- Clean up regularly jar package --> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> </dependency> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz-jobs</artifactId> </dependency>
Customize a Job( Scheduled tasks )
public class ClearImg { @Autowired private JedisPool jedisPool; public void clearImg(){ System.out.println(jedisPool); // Put all the contents Set<String> set = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES); if(set!=null){ // Call the delete method for (String s : set) { QiniuUtils.deleteFileFromQiniu(s); // eliminate redis Junk pictures in jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,s); } } } }
Accessories Spring-jobs Configuration file for
Will make it up to you job Configuration to Spring in
<!-- Register custom Job --> <bean id="jobDemo" class="com.itheima.jobs.ClearImg"></bean>
register JobDetail, The action is responsible for invoking the specified through reflection job
<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!-- Inject the target object --> <property name="targetObject" ref="jobDemo"/> <!-- Inject target method --> <property name="targetMethod" value="clearImg"/> </bean>
Register a trigger , Specify when the task is triggered
<bean id="myTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <!-- Inject JobDetail That is, who will execute --> <property name="jobDetail" ref="jobDetail"/> <!-- Specify the trigger time , be based on Cron expression Specify how often --> <property name="cronExpression"> <value>0 0 0/1 * * ? </value> </property> </bean>
Register a unified dispatching factory , Through this scheduling factory, scheduling tasks
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <!-- Inject multiple triggers --> <property name="triggers"> <list> <!-- trigger 1 --> <ref bean="myTrigger"/> <!-- trigger 2 --> <res bean="xXX"> <!-- .... --> </list> </property> </bean>
Cron expression
Altogether 7 position , What is often used is 6 position
From right to right : second branch when Japan Zhou year
Online generation Cron expression
边栏推荐
猜你喜欢
The markdown plug-in of the browser cannot display the picture
Installation and use of SVN version controller
Google browser chropath plug-in
prometheus告警流程及相关时间参数说明
C # solve the relative path problem using SQLite
文件名设置导致writelines写入报错:OSError: [Errno 22] Invalid argument
Enumeration? Constructor? Interview demo
[system design] proximity service
1098 insertion or heap sort (PAT class a)
Take you to play with the camera module
随机推荐
ThreadLocal digs its knowledge points again
使用aspose-slides将ppt转pdf
unity--newtonsoft.json解析
There is no doubt that this is an absolutely elaborate project
【mysql篇-基础篇】通用语法1
[vivid understanding] the meanings of various evaluation indicators commonly used in deep learning TP, FP, TN, FN, IOU and accuracy
Rockermq message sending mode
手把手带你玩摄像头模组
How do I get the STW (pause) time of a GC (garbage collector)?
[system design] proximity service
The markdown plug-in of the browser cannot display the picture
三道基础面试题总结
1098 Insertion or Heap Sort(堆排序解释)(PAT甲级)
借助原子变量,使用CAS完成并发操作
About the problem that the El date picker Click to clear the parameter and make it null
Installation and usage of source insight tool
Rockermq message sending and consumption mode
小白也能看懂的网络基础 03 | OSI 模型是如何工作的(经典强推)
MYSQL精通-01 增删改
Rman-08137 main library failed to delete archive file