這裡用的是Spring-2.x和Quartz-1.x
裡面涉及到的RecFileQuartz、MessageSendQuartz等類,都是普通的Java類
其中<targetMethod>屬性值就是RecFileQuartz、MessageSendQuartz類中的方法
- <bean id="recfileQuartz" class="com.ecpay.cus.quartz.RecFileQuartz">
- <property name="pbcDao" ref="pbcDao" />
- <property name="nauDao" ref="nauDao" />
- </bean>
- <bean id="messageSendQuartz" class="com.ecpay.cus.quartz.MessageSendQuartz">
- <property name="jfbManager" ref="jfbManager"/>
- </bean>
-
-
- <!-- Spring作業調度 -->
- <!-- 0 0/10 9-23 * * ? : 每天09:00-23:00之間每10分鐘觸發一次 -->
- <!-- 0 */2 * * * ? : 02分鐘觸發一次 -->
- <!-- 0 30 0 * * ? : 每天00:30觸發 -->
- <!-- 0 0 1 * * ? : 每天01:00觸發 -->
- <!-- 0 0 0 1 * ? : 每月01號零點觸發 -->
- <!-- autoStartup='true':SchedulerFactoryBean在初始化後是否馬上啟動Scheduler,默認為true。若設置為false,則需手工啟動Scheduler -->
- <!-- concurrent='false':false為不允許任務並發執行,即第二個job將不會在第一個job完成之前開始執行.默認情況下,jobs是在並行的方式下運行的 -->
- <bean id="quartzJobFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
- <property name="triggers">
- <list>
- <ref bean="genCustomizeRelationTrigger"/>
- <ref bean="sendInfoTrigger"/>
- </list>
- </property>
- <property name="autoStartup" value="true"/>
- </bean>
-
- <bean id="genCustomizeRelationTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
- <property name="jobDetail" ref="genCustomizeRelationJobDetail" />
- <property name="cronExpression" value="0 30 0 * * ?"/>
- </bean>
- <bean id="genCustomizeRelationJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
- <property name="targetObject" ref="recfileQuartz" />
- <property name="targetMethod" value="genRecFileRelation" />
- <property name="concurrent" value="false" />
- </bean>
-
- <bean id="sendInfoTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
- <property name="jobDetail" ref="sendInfoDetail"/>
- <property name="cronExpression" value="0 */10 * * * ?" />
- </bean>
- <bean id="sendInfoDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
- <property name="targetObject" ref="messageSendQuartz" />
- <property name="targetMethod" value="executeSend" />
- <property name="concurrent" value="false" />
- </bean>
下面是MessageSendQuartz.java
- package com.ecpay.cus.quartz;
-
- import com.ecpay.cus.service.JFBBusinessManager;
-
- /**
- * 信息推送
- * @author 玄玉<http://blog.csdn.net/jadyer>
- */
- public class MessageSendQuartz {
- private JFBBusinessManager jfbManager;
- public void setJfbManager(JFBBusinessManager jfbManager) {
- this.jfbManager = jfbManager;
- }
-
- /**
- * 定時執行的方法
- */
- public void executeSend() throws Exception {
- System.out.println("恭喜您:信息推送任務啟動了");
- }
- }
下面是RecFileQuartz.java
- package com.ecpay.cus.quartz;
-
- import org.springframework.transaction.annotation.Transactional;
-
- import com.ecpay.cus.dao.NotActiveUserDAO;
- import com.ecpay.cus.dao.PayBusinessCustomizeDAO;
-
- /**
- * 業務定制對賬文件之作業調度類
- * @author 玄玉<http://blog.csdn.net/jadyer>
- * @create May 4, 2012 12:50:28 PM
- */
- @Transactional
- public class RecFileQuartz {
- private PayBusinessCustomizeDAO pbcDao;
- private NotActiveUserDAO nauDao;
- public void setNauDao(NotActiveUserDAO nauDao) {
- this.nauDao = nauDao;
- }
- public void setPbcDao(PayBusinessCustomizeDAO pbcDao) {
- this.pbcDao = pbcDao;
- }
-
- /**
- * 生成定制關系到數據庫
- */
- @Transactional
- public void genRecFileRelation() {
- System.out.println("恭喜您:Spring定制調度執行了該方法,本行打印的日志就是該方法的第一行代碼");
- }
- }