zoukankan      html  css  js  c++  java
  • Spring3的quartz定时任务

    要使用定时任务,需要将quartz-1.5.2.jar加入lib,没有的话可以从下面地址下载:

    quartz-1.5.2.jar

    有了这个再做个配置文件appctx-quartz.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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
        <bean id="schedulerFactory"    class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
            <property name="triggers">
                <list>
                    <ref local="cronTriggerTest" />
                </list>
            </property>
        </bean> 
        
        <bean id="cronTriggerTest" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail" ref="jobTest" />
            <property name="cronExpression">
                    <value>0 17 21 ? * SAT</value> <!-- FORMAT:second minute hour ? * Weekday -->
            </property>
        </bean>    
        
        <bean id="jobTest"
            class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
            <property name="targetObject" ref="claimScheduler" />
            <property name="targetMethod" value="print" />
        </bean>
        
        <bean id="claimScheduler" class="com.ufo.unknown.quartz.Test">
        </bean>
    </beans>

    被调用的类如下:

    package com.ufo.unknown.quartz;
    
    
    public class Test{
        public void print(){
            System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        }
    }

    然后在周六的21点17分0秒,Test类的print函数就被调用了,控制台输出如下:

    DEBUG (JobRunShell.java:202) - Calling execute on job DEFAULT.jobTest
    DEBUG (CachedIntrospectionResults.java:222) - Getting BeanInfo for class [org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob]
    DEBUG (CachedIntrospectionResults.java:238) - Caching PropertyDescriptors for class [org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob]
    DEBUG (CachedIntrospectionResults.java:250) - Found bean property 'class' of type [java.lang.Class]
    DEBUG (CachedIntrospectionResults.java:250) - Found bean property 'methodInvoker' of type [org.springframework.util.MethodInvoker]
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  • 相关阅读:
    Python接口自动化(四) https请求(SSLError解决办法)
    Python接口自动化(三)post请求四种传送正文方式
    Python接口自动化(二) 发送post请求的接口;发送post【data】;python中字典和json的区别
    requests高级用法
    HDU-1874-畅通工程续 (队列优化)
    Codeforces Round #387 (Div. 2) D. Winter Is Coming
    Codeforces Round #387 (Div. 2) C. Servers
    Codeforces Round #387 (Div. 2) B. Mammoth's Genome Decoding
    Codeforces Round #387 (Div. 2) A. Display Size
    Codeforces Round #386 (Div. 2) B. Decoding
  • 原文地址:https://www.cnblogs.com/heyang78/p/4132046.html
Copyright © 2011-2022 走看看