quartz定時任務實現只執行一次,以後不再執行
阿新 • • 發佈:2019-01-27
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<bean id="publicWebServiceJob" class="cn.org.site.business.quartz.PublicWebServiceScheduleJob" />
<bean id="publicWebServiceJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="publicWebServiceJob" />
<property name="targetMethod" value="doJob"></property>
<!--預設允許併發執行,設定為false 防止併發執行 發生死鎖問題 -->
<property name="concurrent" value="false"/>
</bean>
<!-- quartz一分鐘執行一次的實現方式 -->
<!-- <bean id="publicWebServiceTriggerBean" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="publicWebServiceJobDetail"></property>
<property name="cronExpression" value="0 */1 * * * ?"></property>
<property name="description" value="定時"></property>
</bean>-->
<!-- quartz例項化5秒後執行一次job的方式 -->
<bean id="publicWebServiceTriggerBean" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="publicWebServiceJobDetail" />
<property name="startDelay" value="5000" /> <!-- 啟動延遲 單位/毫秒-->
<property name="repeatCount" value="0" /> <!-- 重複次數 -->
</bean>
<!-- 觸發器-->
<bean id="schedulerFactoryBean-em" lazy-init="false" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="publicWebServiceTriggerBean"/>
</list>
</property>
</bean>
</beans>