项目中定时任务多个如何实现

1.定时任务多个任务的实现配置:

applicationContext-configuration.xml

<!-- 系统调度控制器 -->
    <bean id="statTask"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="shop_stat" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="false" />
    </bean>
    <bean id="stat_cronTrigger"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="statTask" />
        <property name="cronExpression" value="0 */30 * * * ?" />
    </bean>

    <bean id="jobShanGou"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="shanGou_job" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="false" />
    </bean>

    <bean id="job_shanGou"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobShanGou" />
        <property name="cronExpression" value="0 0/1 * * * ?" />
    </bean>


    <bean id="jobOrderExcel_16"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="orderExcel_16" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="true" />
    </bean>

    <bean id="job_OrderExcel_16"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobOrderExcel_16" />
        <property name="cronExpression" value="0 0 16 * * ?" />
    </bean>

    <bean id="jobOrderExcel_10"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="orderExcel_10" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="true" />
    </bean>

    <bean id="job_OrderExcel_10"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobOrderExcel_10" />
        <property name="cronExpression" value="0 0 10 * * ?" />
    </bean>


    <bean id="jobOrderStatus30"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="OrderStatus30" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="true" />
    </bean>

    <bean id="job_OrderStatus30"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobOrderStatus30" />
        <property name="cronExpression" value="0 0 0 ? * *" />
    </bean>


    <bean id="jobOrderStatus50"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="OrderStatus50" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="false" />
    </bean>

    <bean id="job_OrderStatus50"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobOrderStatus50" />
        <property name="cronExpression" value="0 0 0 ? * * " />
    </bean>


    <bean id="jobcouponInfo2"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="couponInfo2" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="false" />
    </bean>

    <bean id="job_couponInfo2"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobcouponInfo2" />
        <property name="cronExpression" value="0 0 0 ? * *" />
    </bean>


    <bean id="jobcancelOrder"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="cancelOrder" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="false" />
    </bean>

    <bean id="job_cancelOrder"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobcancelOrder" />
        <!--<property name="cronExpression" value="0 0/1 * * * ?" />-->
        <property name="cronExpression" value="0 0 0 ? * *" />
    </bean>


    <bean id="jobTask"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="shop_job" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="false" />
    </bean>
    <bean id="job_cronTrigger"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobTask" />
        <property name="cronExpression" value="1 0 0 * * ?" />
    </bean>


    <bean id="jobPYP"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="pYP_Job" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="false" />
    </bean>

    <bean id="job_PYP"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobPYP" />
        <property name="cronExpression" value="0 0/1 * * * ?" />
    </bean>

    <!-- 刷新组员的服务状态 -->
     <bean id="jobTIME"
           class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
         <!-- 调用的类 -->
         <property name="targetObject" ref="fenDa_TimeStates" />
         <!-- 调用类中的方法 -->
         <property name="targetMethod" value="execute" />
         <property name="concurrent" value="false" />
     </bean>

     <bean id="job_times"
           class="org.springframework.scheduling.quartz.CronTriggerBean">
         <property name="jobDetail" ref="jobTIME" />
         <property name="cronExpression" value="0 0/1 * * * ?" /><!-- 每天凌晨1点执行一次  -->
         <!--<property name="cronExpression" value="0 0 1 * * ?" />&lt;!&ndash; 每天凌晨1点执行一次  &ndash;&gt;-->
     </bean>


    <bean id="jobFenDa"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="fenDa_otheListen_Job" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="false" />
    </bean>

    <bean id="job_FenDa"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobFenDa" />
        <property name="cronExpression" value="0 0/10 * * * ?" />
    </bean>

    <bean id="jobTeamStatis"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="teamStatis_Job" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="false" />
    </bean>

    <bean id="job_teamStatis"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobTeamStatis" />
        <property name="cronExpression" value="0 0 1 * * ?" />
    </bean>

    <bean id="jobRankList"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="rankList_Job" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="false" />
    </bean>

    <bean id="job_rankList"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobRankList" />
        <property name="cronExpression" value="0 0/1 * * * ?" />
    </bean>

    <bean id="jobTASKWARNS"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="taskWarns_Job" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="true" />
    </bean>

    <bean id="job_taskWarns"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobTASKWARNS" />
        <property name="cronExpression" value="0 0/1 * * * ?" /><!-- 每隔一分钟执行一次  -->
    </bean>

    <bean id="clear_table"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="clearTable_job" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="false" />
    </bean>
    <bean id="job_clearTable"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="clear_table" />
        <property name="cronExpression" value="0 0 1 * * ?" />
        <!--<property name="cronExpression" value="0 0/1 * * * ?" /> 每分钟执行一次-->
    </bean>

    <bean id="jobLiveRemind"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="liveRemind_Job" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="true" />
    </bean>

    <bean id="job_liveRemind"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobLiveRemind" />
        <property name="cronExpression" value="0 0/1 * * * ?" /><!-- 每隔一分钟执行一次  -->
    </bean>

    <!-- 每隔一天清理一次没收的能量-->
    <bean id="clearEnergyLog"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="clear_energy_log" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="false" />
    </bean>

    <bean id="job_clearEnergyLog"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="clearEnergyLog" />
        <property name="cronExpression" value="0 0 1 * * ?" /><!-- 每天凌晨1点执行一次  -->
    </bean>

    <!-- 每天更新活动状态-->
    <bean id="socialCircleActivityJob"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="socialCircleActivity_job" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="false" />
    </bean>

    <bean id="job_socialCircleActivity"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="socialCircleActivityJob" />
        <!-- 每天凌点过一秒执行一次  -->
        <property name="cronExpression" value="1 0 0 * * ?" />
        <!--<property name="cronExpression" value="0 0/1 * * * ?" />-->
    </bean>

    <bean id="jobHealthyWeek"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="job_healthyWeek" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="false" />
    </bean>

    <bean id="job_healthyWeekNews"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobHealthyWeek" />
        <property name="cronExpression" value="0 0 8 ? * MON" /><!-- 每周一8点执行一次  -->
        <!--<property name="cronExpression" value="0 0/1 * * * ?" />-->
    </bean>

    <bean id="jobSaveChatRecord"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="saveChatRecord_job" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="false" />
    </bean>

    <bean id="job_saveChatRecord"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobSaveChatRecord" />
        <property name="cronExpression" value="0 0 3 * * ?" /><!-- 每天凌晨3点执行一次  -->
        <!--<property name="cronExpression" value="0 0/1 * * * ?" />-->
    </bean>

    <bean id="jobUpdateUserV2ServiceLog"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject" ref="updateUserV2ServiceLog_job" />
        <!-- 调用类中的方法 -->
        <property name="targetMethod" value="execute" />
        <property name="concurrent" value="false" />
    </bean>

    <bean id="job_updateUserV2ServiceLog"
          class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobUpdateUserV2ServiceLog" />
        <property name="cronExpression" value="0 0 0 * * ?" /><!-- 每天凌晨3点执行一次  -->
        <!--<property name="cronExpression" value="0 0/1 * * * ?" />-->
    </bean>

    <bean id="schdulerFactory" lazy-init="false"
          class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="job_OrderStatus30" />
                <ref bean="job_OrderStatus50" />
                <ref bean="job_couponInfo2" />
                <ref bean="job_teamStatis"/>
                <ref bean="job_times"/> <!--定时任务刷新会员-->
                <ref bean="job_cancelOrder"/>
                <ref bean="job_clearTable"/>
                <ref bean="job_clearEnergyLog"/>
                <ref bean="job_socialCircleActivity"/>
                <ref bean="job_healthyWeekNews"/>
                <!--<ref bean="job_appArticlePush"/>-->
                <ref bean="job_saveChatRecord"/>
                <ref bean="job_updateUserV2ServiceLog"/>
            </list>
        </property>
    </bean>

2.在代码中直接实现方法就可以:

 package com.shopping.view.web.action;/***
  * 刷新签约小组的服务的定时任务
  */
 @Component("fenDa_TimeStates")
 public class FenDamemberActionV2 {
     public void execute() {
         System.out.println("进入更新小组成员的任务");
     //书写自己的逻辑 处理操作就可以
  }
}

 

posted @ 2019-06-09 10:36  坠落凡尘的魔鬼  阅读(1139)  评论(0编辑  收藏  举报