Spring+Quartz配置定時(shí)任務(wù)實(shí)現(xiàn)代碼
作為一個(gè)優(yōu)秀的開(kāi)源調(diào)度框架,Quartz 具有以下特點(diǎn):
強(qiáng)大的調(diào)度功能,例如支持豐富多樣的調(diào)度方法,可以滿(mǎn)足各種常規(guī)及特殊需求;
靈活的應(yīng)用方式,例如支持任務(wù)和調(diào)度的多種組合方式,支持調(diào)度數(shù)據(jù)的多種存儲(chǔ)方式;
分布式和集群能力,Terracotta 收購(gòu)后在原來(lái)功能基礎(chǔ)上作了進(jìn)一步提升。
另外,作為 Spring 默認(rèn)的調(diào)度框架,Quartz 很容易與 Spring 集成實(shí)現(xiàn)靈活可配置的調(diào)度功能。
代碼如下
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" /> <!--目標(biāo)Job-->
</property>
<property name="targetMethod">
<value>doCreate</value> <!--目標(biāo)方法-->
</property>
<property name="concurrent">
<value>false</value> <!--定時(shí)任務(wù)串行-->
</property>
</bean>
4、
<bean id="jobService" class="com.task.CreateFileAndStuff"></bean>
5、
在CreateFileAndStuff.Java
/**
* 開(kāi)始生成
*/
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);
}
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
java 基于maven多模塊合并打包部署的操作過(guò)程
這篇文章主要介紹了java 基于maven多模塊合并打包部署的操作過(guò)程,本文通過(guò)實(shí)例代碼圖文相結(jié)合給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02
Java實(shí)現(xiàn)簡(jiǎn)易學(xué)籍管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)簡(jiǎn)易學(xué)籍管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
spring boot 開(kāi)發(fā)soap webservice的實(shí)現(xiàn)代碼
這篇文章主要介紹了spring boot 開(kāi)發(fā)soap webservice的實(shí)現(xiàn)代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-01-01
java如何拷貝復(fù)制對(duì)象和集合問(wèn)題
這篇文章主要介紹了java如何拷貝復(fù)制對(duì)象和集合問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-09-09
Spring深入講解實(shí)現(xiàn)AOP的三種方式
Spring的AOP就是通過(guò)動(dòng)態(tài)代理實(shí)現(xiàn)的,使用了兩個(gè)動(dòng)態(tài)代理,分別是JDK的動(dòng)態(tài)代理和CGLIB動(dòng)態(tài)代理,本文重點(diǎn)給大家介紹下Spring?Aop的三種實(shí)現(xiàn),感興趣的朋友一起看看吧2022-05-05

