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ù)的多種存儲方式;
分布式和集群能力,Terracotta 收購后在原來功能基礎(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); } }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. python爬蟲實(shí)戰(zhàn)之制作屬于自己的一個(gè)IP代理模塊2. HTML 絕對路徑與相對路徑概念詳細(xì)3. .NET6打包部署到Windows Service的全過程4. 使用FormData進(jìn)行Ajax請求上傳文件的實(shí)例代碼5. 解決ajax請求后臺,有時(shí)收不到返回值的問題6. Python編寫nmap掃描工具7. 如何在jsp界面中插入圖片8. 基于javaweb+jsp實(shí)現(xiàn)企業(yè)財(cái)務(wù)記賬管理系統(tǒng)9. Ajax返回值類型與用法實(shí)例分析10. .Net Core和RabbitMQ限制循環(huán)消費(fèi)的方法
