您的位置:首页技术文章
文章详情页

Spring+Quartz配置定时任务实现代码

【字号: 日期:2023-09-07 14:23:30浏览:10作者:猪猪

作为一个优秀的开源调度框架,Quartz 具有以下特点:

强大的调度功能,例如支持丰富多样的调度方法,可以满足各种常规及特殊需求;

灵活的应用方式,例如支持任务和调度的多种组合方式,支持调度数据的多种存储方式;

分布式和集群能力,Terracotta 收购后在原来功能基础上作了进一步提升。

另外,作为 Spring 默认的调度框架,Quartz 很容易与 Spring 集成实现灵活可配置的调度功能。

代码如下

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' /> <!--目标Job--> </property> <property name='targetMethod'> <value>doCreate</value> <!--目标方法--> </property> <property name='concurrent'> <value>false</value> <!--定时任务串行--> </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); } }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持好吧啦网。

标签: Spring
相关文章: