Spring+Quartz配置定時任務實現(xiàn)代碼
作為一個優(yōu)秀的開源調度框架,Quartz 具有以下特點:
強大的調度功能,例如支持豐富多樣的調度方法,可以滿足各種常規(guī)及特殊需求;
靈活的應用方式,例如支持任務和調度的多種組合方式,支持調度數(shù)據的多種存儲方式;
分布式和集群能力,Terracotta 收購后在原來功能基礎上作了進一步提升。
另外,作為 Spring 默認的調度框架,Quartz 很容易與 Spring 集成實現(xiàn)靈活可配置的調度功能。
代碼如下
1、
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="createFileAndStuffTrigger"/>
</list>
</property>
</bean>
2、
<bean id="createFileAndStuffTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="startDelay"><value>5000</value></property>
<property name="repeatCount"><value>-1</value></property>
<property name="repeatInterval"><value>36000000</value></property>
<property name="jobDetail"><ref bean="createFileAndStuffTask" /></property>
</bean>
3、
<bean id="createFileAndStuffTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="jobService" /> <!--目標Job-->
</property>
<property name="targetMethod">
<value>doCreate</value> <!--目標方法-->
</property>
<property name="concurrent">
<value>false</value> <!--定時任務串行-->
</property>
</bean>
4、
<bean id="jobService" class="com.task.CreateFileAndStuff"></bean>
5、
在CreateFileAndStuff.Java
/**
* 開始生成
*/
public synchronized void doCreate(){
if ("yes".equals(ConfigUtil.createFileAndSuffSwitch())) {
List<Map<String ,Object>> switchDList=this.getBusInfo();
if(null==switchDList || 0==switchDList.size()) return;
this.doCreateForLoopSwitch(switchDList,one_number);
}
}
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
spring boot 開發(fā)soap webservice的實現(xiàn)代碼
這篇文章主要介紹了spring boot 開發(fā)soap webservice的實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-01-01

