(可是延遲啓動的功能,好像只有SimpleTriggerFactoryBean具有)mysql
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd"> <!--調度器工廠--> <bean id="testScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <!--兩個定時器--> <!--從mysql同步到redis和memory--> <ref bean="initSyncJob"></ref> <!--從redis同步到memeory到mysql --> <ref bean="triggerSyncJob"></ref> </list> </property> <property name="autoStartup" value="true"></property> </bean> <!-- 第一個定時器 start --> <!--觸發點--> <bean id="initSyncJob" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean"> <property name="jobDetail" ref="initSyncCheck"> </property> <property name="repeatInterval"> <!-- 2秒一次--> <value>2000</value> </property> <!-- 啓動開始時間 --> <property name="startDelay"><value>0</value></property> <!--重複次數:0 重複次數和重複間隔必須同時存在或同時爲0--> <!--去掉的話按結束時間算 --> <property name="repeatCount"> <value>0</value> </property> <!-- 重複間隔 0s --> <property name="repeatInterval" value="0"/> </bean> <!--定時器具體做業--> <bean id="initSyncCheck" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="initJob"> </property> <property name="targetMethod" value="job"></property> <property name="concurrent" value="false"/> </bean> <bean id="initJob" class="com.test.InitTask"/> </beans> <!-- 第二個定時器 --> <!--觸發點--> <bean id="triggerSyncJob" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean"> <property name="jobDetail" ref="syncCheck" /> <property name="startDelay" value="5000" /><!-- 調度工廠實例化後,通過5秒開始執行調度 --> <property name="repeatInterval" value="2000" /><!-- 每2秒調度一次 --> </bean> <!--定時器具體做業--> <bean id="syncCheck" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="syncJob"> </property> <property name="targetMethod" value="job"></property> <property name="concurrent" value="false"/> </bean> <bean id="syncJob" class="com.test.SyncTask"/> <!-- 若是使用CronTriggerFactoryBean做爲觸發點 --> <!--觸發點--> <bean id="initSyncJob" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="jobDetail" ref="initSyncCheck"> </property> <property name="cronExpression"> <!--每隔一分鐘執行一次 --> <!--<value>0 */1 * * * ?</value>--> <!--每隔1秒執行一次 --> <value>*/1 * * * * ?</value> </property> </bean>
<!-- quartz jar --> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>2.2.1</version> </dependency> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz-jobs</artifactId> <version>2.2.1</version> </dependency> <!-- quartz jar -->
原文:https://blog.csdn.net/c75836145/article/details/53423625 redis