zoukankan      html  css  js  c++  java
  • Spring集成Quartz定时任务 ---- 定时执行

    一、依赖JAR包

    <dependency>
     <groupId>org.quartz-scheduler</groupId>
     <artifactId>quartz</artifactId>
     <version>1.8.4</version>
    </dependency>
    

      

    <dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-webmvc</artifactId>
     <version>3.0.5.RELEASE</version>
    </dependency
    

    二、配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:task="http://www.springframework.org/schema/task"
    	xsi:schemaLocation="
         http://www.springframework.org/schema/beans 
         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
         http://www.springframework.org/schema/task 
         http://www.springframework.org/schema/task/spring-task.xsd">
    	
    		<!--管理触发器的总设置 -->
    	<bean autowire="no"
    		class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    		<property name="triggers">
    			<list>
    				<ref local="QuartzSchedulerTrigger" />
    			</list>
    		</property>
    	</bean>
    
    	<bean id="QuartzScheduler"
    		class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    		<property name="targetObject">
    			<bean
    				class="com.service.task.QuartzSchedulerTask" />   //定义业务逻辑处理类
    		</property>
    		<property name="targetMethod">
    			<value>autoChecked</value>
    		</property>
    		<property name="concurrent">
    			<value>false</value>
    		</property>
    	</bean>
    
    	<bean id="QuartzSchedulerTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    		<property name="jobDetail">
    			<ref bean="QuartzScheduler" />
    		</property>
    		<property name="cronExpression">   //增加调度触发器
    			<!--秒 0-59 , - * / 分 0-59 , - * / 小时 0-23 , - * / 日期 1-31 , - * ? / L 
    				W C 月份 1-12 或者 JAN-DEC , - * / 星期 1-7 或者 SUN-SAT , - * ? / L C # 年(可选) 留空, 
    				1970-2099 , - * / -->
    			<value>0 0/1 * * * ?</value>
    		</property>
    	</bean>
    	
    
    </beans>
    

      三、分析

    Cron/

    cronExpression

    表达式“0 */1 * * * ?”意为:从0秒开始,每1分钟执行一次。

    triggers属性中,我们可以增加多个触发器。

    到此,Spring已经与Quartz完美的结合了,我们接下来的工作就是启动系统,开始调度了。

    其他参考博客:http://www.cnblogs.com/obullxl/archive/2011/07/10/spring-quartz-cron-integration.html

    http://kevin19900306.iteye.com/blog/1397744

  • 相关阅读:
    解决无线打印机休眠后掉线无法进行局域网打印的问题
    快速为某个目录的verilog文件生成filelist
    使用Visual Studio的Spy++查找弹窗广告进程
    【转载】verilog语法之generate语句的基本认识
    补码(为什么按位取反再加一):告诉你一个其实很简单的问题
    【转载】EDID的简介和解析
    win32diskimager 谨慎使用
    UXE的一些使用归纳
    如何在win8或win10系统里添加inf驱动程序
    STM32 USB HID
  • 原文地址:https://www.cnblogs.com/binbang/p/4893814.html
Copyright © 2011-2022 走看看