要使用定时任务,需要将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]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Spring3的quartz定时任务的更多相关文章

  1. Quartz定时任务学习(二)web应用/Quartz定时任务学习(三)属性文件和jar

    web中使用Quartz 1.首先在web.xml文件中加入 如下内容(根据自己情况设定) 在web.xml中添加QuartzInitializerServlet,Quartz为能够在web应用中使用 ...

  2. quartz定时任务框架的使用

    quartz定时任务时间设置 这些星号由左到右按顺序代表 :     *    *     *     *    *     *   *                                 ...

  3. Quartz定时任务学习(二)web应用

    web中使用Quartz 1.首先在web.xml文件中加入 如下内容(根据自己情况设定) 在web.xml中添加QuartzInitializerServlet,Quartz为能够在web应用中使用 ...

  4. Quartz定时任务使用小记(11月22日)

    骤然接触quartz,先从小处着手,why,what,how quartz定时任务: 为什么使用quartz定时任务,以及定时任务在实际应用场景下的特定需求. 1.用户方面的需要,为了提供更好的使用体 ...

  5. quartz定时任务时间配置

    quartz定时任务时间设置描述(2011-03-03 16:23:50)转载▼标签: quartz时间it 分类: 凌乱小记  这些星号由左到右按顺序代表 :     *    *     *    ...

  6. 对quartz定时任务的初步认识

    已经好久没有写技术博文了,今天就谈一谈我前两天自学的quartz定时任务吧,我对quartz定时任务的理解,就是可以设定一个时间,然后呢,在这个时间到的时候,去执行业务逻辑,这是我的简单理解,接下来看 ...

  7. Spring整合Quartz定时任务执行2次,Spring定时任务执行2次

    Spring整合Quartz定时任务执行2次,Spring定时任务执行2次 >>>>>>>>>>>>>>>&g ...

  8. Quartz 定时任务时间设置

    转自https://blog.csdn.net/zdx1515888659/article/details/79158169 quartz定时任务时间设置: 这些星号由左到右按顺序代表 : * * * ...

  9. quartz定时任务及时间设置

    quartz 定时任务时间设置1.这些星号由左到右按顺序代表 :     *    *     *     *    *     *   *                               ...

随机推荐

  1. Vitamio 视频播放

     资料总结 Vitamio官网:https://www.vitamio.org 源码地址:https://github.com/yixia/VitamioBundle 最佳教程:大名鼎鼎的农民伯伯博客 ...

  2. 使序列有序的最少交换次数(minimum swaps)

    交换相邻两数 如果只是交换相邻两数,那么最少交换次数为该序列的逆序数. 交换任意两数 数字的总个数减去循环节的个数?? A cycle is a set of elements, each of wh ...

  3. [bzoj2127]happiness——最小割

    这个题太恶心了...并不想继续做了... 本代码在bzoj上TLE! 大致说一下思路: 建立ST,首先由S连边(S,u,a)a代表学文的分数,连向T(u,T,b)b表示学理的分数,这样构造出了两个人独 ...

  4. OpenGL入门学习(四)

    http://blog.csdn.net/sun6255028/article/details/5090055 OpenGL支持两种颜色模式:一种是RGBA,一种是颜色索引模式.无论哪种颜色模式,计算 ...

  5. ScrollView下嵌套GridView或ListView默认不在顶部的解决方法

    自定义ScrollView重写下面的方法 /* ScrollView下嵌套GridView或ListView默认不在顶部的解决方法*/ @Override protected int computeS ...

  6. BufferedInputStream&BufferedOutputStream

    使用字符缓冲区相关实现copy文件: public static void main(String[] args) { //创建文件对象指定要拷贝的文件路径(源文件),文件须存在,测试用例不做判断 F ...

  7. Python-mysql索引

    MySQL索引的概念 索引是一种特殊的文件(InnoDB数据表上的索引是表空间的一个组成部分),它们包含着对数据表里所有记录的引用指针.更通俗的说,数据库索引好比是一本书前面的目录,能加快数据库的查询 ...

  8. 使用windos电脑模拟搭建web集群(一)

    资源规划 1.环境准备 centos7.2 虚拟机 13个 可以先配置一台,做好基础优化,然后克隆13台分布在 windos宿主机上 两台windos笔记  都是8g的内存 一台有点内存吃紧. 没有物 ...

  9. C/C++/C#程序如何打成DLL动态库

    C/C++程序如何打成DLL动态库:1.在VS中新建main.h,添加如下内容:extern "C" _declspec(dllexport) int onLoad(); 2.新建 ...

  10. (1)C# 创建ef sqlserver

    连接sql 如果报错不能连接的错误 把这三个IP地址的端口号设置上,并启用.第一个18.6是本机ip,之后就可以测试了 最后重启服务器