System.out.println("不知道該怎麼刪除這個Java代碼框了");
使用quartz框架可以完成定時任務處理即Job,比如有時候我們設置1個Job每隔5分鐘執行1次,後來會發現當前Job啓動的時候上一個Job還沒有運行結束,這顯然不是我們期望的,此時可以設置quartz中的參數,來確保Job不併發執行
1. quartz未與Spring結合
//可以通過在實現Job接口的類上加註解的方式
@DisallowConcurrentExecution
public class TestJob implements Job{
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
System.out.println("test");
}
}
2. quartz與spring集成,設置配置文件concurrent參數爲false
<bean id="fetchOneJob" class="hm.com.job.FetchDataFromOrgJDBC"/>
<bean id="fetchOneJobTask"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="concurrent" >
<value>false</value>
</property>
<property name="targetObject">
<ref bean="fetchOneJob" />
</property>
<property name="targetMethod">
<value>work</value>
</property>
</bean>
<bean id="fetchOneJobTime" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="fetchOneJobTask" />
</property>
<property name="cronExpression">
<value>0 0/3 * * * ?</value>
</property>
</bean>
<bean id="startFetchOneJobTime" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="fetchOneJobTime" />
</list>
</property>
</bean>