Spring-quartz-spring定时任务

一:创建定时任务执行的类

public class quartzJob {

    /** 日志 */
    private static Log log = LogFactory.getLog(quartzJob.class);
    public  void  work() throws Exception {
        try {
            log.error("----------------------->定时下载解析影像资料开始------------->");
          
            log.error("----------------------->定时下载解析影像资料结束------------->");
            } catch (Exception e) {
            log.error(e.getMessage());
            throw new Exception(e.getMessage(),e);
        
        }
    }
    
}

二:指定目录下创建springquartz配置文件SpringQuartzJob.xml(文件名自定义)

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

    <!-- ###################################################### spring 高级job #########################-->
        <!-- 总调度,用于启动定时器 -->
    <bean id="schedulerFactory"
        class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                 <ref bean="SyncDataTask" /> 
            </list>
        </property>
    </bean>
    
    
    
    
       <!--1 配置一个触发器 -->
    <bean id="SyncDataTask" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="SyncDataJobTask"></property>
        <!-- 1:秒 2:分3:小时4:月份中的日期(1-31)5:月份(1-12或JAN-DEC)6:星期中的日期(1-7或SUN-SAT)7:年份(1970-2099) -->
        <property name="cronExpression" value="0 */1 * * * ?"></property> <!--0 */20 * * * ?=======0 30 23 * * ?-->
    </bean>
    <!--2 配置需要定时的bean类 -->
    <bean id="SyncDataJob" class="cn.gov.pbc.mimis.quartz.quartzJob"></bean>
    <!--3 配置任务的具体类和方法 -->
    <bean id="SyncDataJobTask"
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 要调用的bean -->
        <property name="targetObject" ref="SyncDataJob"></property>
        <!-- 要调用的Method -->
        <property name="targetMethod" value="work"></property>
        <!-- 是否并发,false表示 如果发生错误也不影响下一次的调用 -->
        <property name="concurrent" value="false"></property>
    </bean>
    
    
    

</beans>
 

三:web.xml里面配置要加载的quartz配置文件

/WEB-INF/classes/config/quartz/SpringQuartzJob.xml,

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值