Spring+Quartz配置定時(shí)任務(wù)實(shí)現(xiàn)代碼
作為一個(gè)優(yōu)秀的開源調(diào)度框架,Quartz 具有以下特點(diǎn):
強(qiáng)大的調(diào)度功能,例如支持豐富多樣的調(diào)度方法,可以滿足各種常規(guī)及特殊需求;
靈活的應(yīng)用方式,例如支持任務(wù)和調(diào)度的多種組合方式,支持調(diào)度數(shù)據(jù)的多種存儲(chǔ)方式;
分布式和集群能力,Terracotta 收購(gòu)后在原來功能基礎(chǔ)上作了進(jìn)一步提升。
另外,作為 Spring 默認(rèn)的調(diào)度框架,Quartz 很容易與 Spring 集成實(shí)現(xiàn)靈活可配置的調(diào)度功能。
代碼如下
1、
<bean class='org.springframework.scheduling.quartz.SchedulerFactoryBean'> <property name='triggers'> <list> <ref local='createFileAndStuffTrigger'/> </list> </property> </bean>
2、
<bean 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 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 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); } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 基于PHP做個(gè)圖片防盜鏈2. ASP.NET MVC使用Boostrap實(shí)現(xiàn)產(chǎn)品展示、查詢、排序、分頁(yè)3. XML在語音合成中的應(yīng)用4. asp.net core 認(rèn)證和授權(quán)實(shí)例詳解5. .NET中實(shí)現(xiàn)對(duì)象數(shù)據(jù)映射示例詳解6. php使用正則驗(yàn)證密碼字段的復(fù)雜強(qiáng)度原理詳細(xì)講解 原創(chuàng)7. ASP.NET MVC把數(shù)據(jù)庫(kù)中枚舉項(xiàng)的數(shù)字轉(zhuǎn)換成文字8. 如何使用ASP.NET Core 配置文件9. jscript與vbscript 操作XML元素屬性的代碼10. 基于javaweb+jsp實(shí)現(xiàn)企業(yè)車輛管理系統(tǒng)
