定时任务-spring-quartz

Maven

<dependency>
    <groupId>org.quartz-scheduler</groupId>
    <artifactId>quartz</artifactId>
    <version>1.8.6</version>
</dependency>
<dependency>
    <groupId>org.fusesource</groupId>
    <artifactId>sigar</artifactId>
    <version>1.6.4</version>
</dependency>

web.xml

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/config/applicationContext-base.xml;
            /WEB-INF/config/applicationContext-quartz.xml;
        </param-value>
</context-param>

applicationContext-quartz.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
    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/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- 定时任务调度器,负责对所以加入队列的触发器定时触发 -->
    <bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <!-- <ref bean="workflowJobTrigger" /> -->
                <!-- <ref bean="jobSchedulerTrigger" /> -->
            <!--    <ref bean="cpCountSignJobTrigger" /> -->
            </list>
        </property>
    </bean>

    <!-- 异步任务调度 -->
    <bean id="jobSchedulerTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobSchedulerTask" />
        <property name="cronExpression">
            <!-- 每隔两分钟 -->
            <value>0 0/2 * * * ?</value>
        </property>
    </bean>

    <bean id="jobSchedulerTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="jobScheduler" />
        <property name="targetMethod" value="doSchedule" />
        <property name="concurrent" value="false" /> <!--将并发设置为false--> 
    </bean>

    <bean id="jobScheduler" class="com.aiso.basic.job.JobInfoScheduler" />

    <!-- 轮询 -->
    <bean id="cpCountSignJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="cpCountSignJobTask" />
        <property name="cronExpression">
            <value>0 0/5 * * * ?</value>
        </property>
    </bean>

    <bean id="cpCountSignJobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="cpCountSignJobScheduler" />
        <property name="targetMethod" value="saveCpCountSign" />
        <property name="concurrent" value="false" /> <!--将并发设置为false--> 
    </bean>

    <bean id="cpCountSignJobScheduler" class="com.aiso.index.job.CpCountSignJob" />


</beans>

定时执行的类

public class CpCountSignJob {
    public void saveCpCountSign() {

        if (this.log.isDebugEnabled()) {
            this.log.debug("轮询任务开始执行!");
        }
        //TODO
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猿与禅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值