spring Quartz多个定时任务的配置

来源:互联网 发布:淘宝整点抢购技巧 编辑:程序博客网 时间:2024/06/05 03:09

1,配置文件与spring整合,需要在spring 的总配置中一入或者在web.xml中spring监听中加上

spring-task.xml

注:定时器出触发的时间,根据需要自己设置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context

    http://www.springframework.org/schema/context/spring-context.xsd">

<!-- spring自动任务调度器配置 --> 


              <!-- 要调用的工作类 -->  

   <bean id="marketSyncAppOrderReqService" class="com.mogu.service.marketSyncAppOrderReqService"></bean>  

   <bean id="syncRuitongService" class="com.mogu.service.syncRuitongService"></bean> 


<!--任务配置列表-->

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

<!--调用的类->

        <property name="targetObject">
            <ref bean="marketSyncAppOrderReqService"/>

        </property>

<!--调用类中的方法-->

        <property name="targetMethod">
            <value>sendSyncEmail</value>
        </property>
    </bean>

   


<!--触发器配置,时间指定-->
    <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
       <property name="jobDetail">
           <ref bean="jobtask"/>

       </property>

<!--cron表达式-->

       <property name="cronExpression">
           <value>0 0/30 * * * ? *</value>
       </property>
   </bean>

  

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

<!--调用的类->

        <property name="targetObject">

            <ref bean="syncRuitongService"/>

        </property>

<!--调用类中的方法->

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

    </bean>


<!--触发器配置,时间指定-->

      <bean id="cronTrigger1" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
       <property name="jobDetail">
           <ref bean="jobtask1"/>

       </property>

<!--cron表达式-->

       <property name="cronExpression">

<!-- 每天每隔5分钟执行一次 <value>0 0/5 * * * ?</value> -->

         <value>0 0/5 * * * ? *</value>
       </property>
   </bean>

  

<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->

   <bean id="startQuertz" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">

       <property name="triggers">

 <!-- 触发器列表    -->

           <list>
               <ref bean="cronTrigger"/>
               <ref bean="cronTrigger1"/>
           </list>
       </property>
     <property name="quartzProperties">
           <props>
              <prop key="org.quartz.threadPool.threadCount">1</prop>
              <prop key="org.quartz.threadPool.threadPriority">2</prop>
           </props>
       </property>
   </bean>
</beans>
0 0
原创粉丝点击