Spring集成Quartz定时器配置流程(基础版)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Maskkiss/article/details/80138392

一、前言

    由于平常接触的项目多为金融项目,很多时候需要每天统计昨天的报表数据,实时维护某些字段等;因此对于Quartz的认识较早一些;它可以很轻易的集成到Spring框架中去,非常好用;

二、引入的包

    需要引入以下jar包:quartz.jar,spring-context-support.jar,commons-collections-3.2.jar

三、Quartz配置

    3.1 线程执行器配置,用于任务注册

    <bean id="executor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">  
<property name="corePoolSize" value="10" />  
<property name="maxPoolSize" value="100" />  
<property name="queueCapacity" value="500" />  

    </bean>

    3.2 业务对象,将需要添加定时任务调度的类配置到这里

    <bean name="checkReport" class="com.byhj.batch.process.report.CheckReport" />

    3.3 调度业务,除了蓝体字其他可以不变

    <bean id="checkReportService" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">

           <!-- 要调用的对象 -->

           <property name="targetObject"ref="checkReport"></property>

           <!-- 要执行的方法名称 -->

           <property name="targetMethod"value="excute"></property>

扫描二维码关注公众号,回复: 2928969 查看本文章

           <!-- 如果前一个任务还没有结束第二个任务不会启动 false -->

           <property name="concurrent"value="false"></property>

   </bean>

3.4 调度触发器

    <bean id="checkReportTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="checkReportService" />
<property name="cronExpression" value="0/20 * * * * ?" />//每20秒跑一次

    </bean>

3.5 调度工厂

<bean id="schedulerBean" 
class="org.springframework.scheduling.quartz.SchedulerFactoryBean" 
lazy-init="false">
<property name="triggers">
<list>
<!-- 批量跑批管理 -->
<ref bean="checkReportTrigger" />
</list>
</property>

</bean>

3.6 开始运行

    加载配置文件就可以执行了



    

猜你喜欢

转载自blog.csdn.net/Maskkiss/article/details/80138392
今日推荐