- 浏览: 62057 次
- 性别:
- 来自: 杭州
-
文章分类
最新评论
-
tinguo002:
这是非常非常好的上传下载事例,
对我帮助非常大,灰常灰常感 ...
java文件上传下载 -
8108498:
也是一种可行方法!对于第三种情况,我在网上看到的:
方法一
& ...
Hibernate中用hql查询部分字段 -
haikn:
还是搞不明白 !!
CSS position 属性
Spring Quartz定时详情
第四步,配置一个调度器。在Spring配置文件中配置调度器类SchedulerFactoryBean。
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!-- 我们的任务 --> <bean name=" reportTask " class= "org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass" value=" BusinessReport " /> </bean> <!-- 触发器 --> <bean id="cronTrigger" class= "org.springframework.scheduling.quartz.CronTriggerBean"> <!-- 指向我们的任务 --> <property name="jobDetail" ref=" reportTask " /> <!-- 每月1日凌晨1点运行 --> <property name="cronExpression" value="0 0 1 1 * ?" /> </bean> <!-- 调度器 --> <bean class= "org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list><!-- 触发器列表--> <ref bean="cronTrigger" /> </list> </property> </bean> </beans>
附:cronExpression表达式解释:
字段 允许值 允许的特殊字符
秒 0-59 , - * /
分 0-59 , - * /
小时 0-23 , - * /
日期 1-31 , - * ? / L W C
月份 1-12 或者 JAN-DEC , - * /
星期 1-7 或者 SUN-SAT , - * ? / L C #
年(可选) 留空, 1970-2099 , - * /
0 0 12 * * ?---------------在每天中午12:00触发
0 15 10 ? * *---------------每天上午10:15 触发
0 15 10 * * ?---------------每天上午10:15 触发
0 15 10 * * ? *---------------每天上午10:15 触发
0 15 10 * * ? 2005---------------在2005年中的每天上午10:15 触发
0 * 14 * * ?---------------每天在下午2:00至2:59之间每分钟触发一次
0 0/5 14 * * ?---------------每天在下午2:00至2:59之间每5分钟触发一次
0 0/5 14,18 * * ?---------------每天在下午2:00至2:59和6:00至6:59之间的每5分钟触发一次
0 0-5 14 * * ?---------------每天在下午2:00至2:05之间每分钟触发一次
0 10,44 14 ? 3 WED---------------每三月份的星期三在下午2:00和2:44时触发
0 15 10 ? * MON-FRI---------------从星期一至星期五的每天上午10:15触发
0 15 10 15 * ?---------------在每个月的每15天的上午10:15触发
0 15 10 L * ?---------------在每个月的最后一天的上午10:15触发
0 15 10 ? * 6L---------------在每个月的最后一个星期五的上午10:15触发
0 15 10 ? * 6L 2002-2005---------------在2002, 2003, 2004 and 2005年的每个月的最后一个星期五的上午10:15触发
0 15 10 ? * 6#3---------------在每个月的第三个星期五的上午10:15触发
0 0 12 1/5 * ?---------------从每月的第一天起每过5天的中午12:00时触发
0 11 11 11 11 ?---------------在每个11月11日的上午11:11时触发.
参考资料:
1.http://www.springframework.org Spring的官方网站
2.http://www.opensymphony.com/quartz/ Quartz的官方网站
程序逻辑:web.xml添加
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/config/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> applicationContext.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.0.xsd"> <bean id="remindQuartz" class="test.quartz.RemindQuartz"/> <bean id="remindQuartzTask" class= "org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="remindQuartz" /> <property name="targetMethod" value="perform" /> <property name="concurrent" value="false" /> </bean> <!-- 调度器 --> <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="remindQuartzTask" /> <property name="cronExpression" value="0 0 1 1 * ?" /> </bean> </beans>
附:实际代码*
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" xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd "> <!-- quartz scheduler实例在spring中的初始化和自动运行 --> <bean id="timerJob" class="com.eduwo.application.web.evaluationSheets.TimerJob"> <property name="evaluationSheetService"> <ref bean="evaluationSheetService"/> </property> </bean> <bean id="methodInvokingJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"><ref bean="timerJob"/></property> <property name="targetMethod"><value>doJob</value></property> <property name="concurrent" value="false"/> </bean> <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="methodInvokingJobDetail"/> </property> <property name="cronExpression" value="0 0/60 * ? * * *" /> </bean> <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false"> <property name="configLocation" value="classpath:quartz.properties" /> <property name="triggers"> <list> <ref local="simpleTrigger"/> </list> </property> </bean> </beans>
JAVA类:
package com.eduwo.application.web.evaluationSheets; import java.util.Date; import org.apache.log4j.Logger; import com.eduwo.application.service.evaluationSheets.EvaluationSheetService; public class TimerJob { Logger logger=Logger.getLogger(TimerJob.class); private EvaluationSheetService evaluationSheetService; public EvaluationSheetService getEvaluationSheetService() { return evaluationSheetService; } public void setEvaluationSheetService( EvaluationSheetService evaluationSheetService) { this.evaluationSheetService = evaluationSheetService; } public void doJob(){ Date d =new Date(); logger.info("Quartz begin ------------------------------"+d.toLocaleString()+"-----"+d.getHours()); //评估单过期处理 evaluationSheetService.updateExpiredEvaluationSheet(); logger.info("Quartz end ------------------------------"); } } public void updateExpiredEvaluationSheet() { // TODO Auto-generated method stub Date date=new Date(System.currentTimeMillis()-2*24*60*60*1000); SimpleDateFormat formattxt=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String timejob=formattxt.format(date); String hql="select count(*) from ComTevaluationsheet sheet where sheet.updatedate is not null" +" and sheet.expired='0' and sheet.status in ('1','2') and sheet.updatedate<=to_date('" + timejob + "'," + "'" + "yyyy-mm-dd hh24:mi:ss')"; List list=new ArrayList(); list=this.get(hql); int count=0; if(list!=null&&list.size()>0) count=(Integer)list.get(0); if(count>0){ System.out.println("start---"); hql="select sheet from ComTevaluationsheet sheet where sheet.updatedate is not null" +" and sheet.expired='0' and sheet.updatedate<=to_date('" + timejob + "'," + "'" + "yyyy-mm-dd hh24:mi:ss')"; list = this.get(hql); for (int i = 0; i < list.size(); i++) { ComTevaluationsheet comTevaluationsheet=(ComTevaluationsheet) list.get(i); comTevaluationsheet.setExpired("1"); comTevaluationsheet.setStatus("3"); //this.updateComTevaluationsheet(comTevaluationsheet); } } }
发表评论
-
spring定时器表达式
2011-01-17 10:27 1000一个Cron-表达式是一 ... -
spring多个定时任务job.xml配置
2011-01-17 10:26 1249<?xml version="1.0" ... -
c3p0在spring下的配置过程
2010-12-03 18:14 908(1) 在hibernate.properties中添加: ... -
c3p0在spring的配置(详解)
2010-12-03 18:13 788C3P0是一个开放源代码的 ... -
Xmemcached使用之与Spring整合
2010-12-03 18:12 13421 简介Xmemcached是一个高性能的基于java n ... -
Spring中Quartz的配置
2010-12-03 18:11 698各种企业应用几乎都会碰到任务调度的需求,就拿论坛来说:每隔半个 ...
相关推荐
Spring Quartz 定时器示例(Web工程版),欢迎下载。
Spring 中的 Quartz 配置-Spring 定时器-java 定时器 在 Spring 框架中,Quartz 是一个非常流行的开源作业调度器,可以实现任务的定时执行。在本篇文章中,我们将讨论如何在 Spring 中配置 Quartz,以实现 Java ...
Spring Quartz定时器 Spring Quartz定时器 Spring Quartz定时器 Spring Quartz定时器
Spring Quartz定时器是Java开发中常用的一个任务调度框架,它结合了Spring框架的强大功能与Quartz的灵活性,使得开发者能够方便地在应用中实现定时任务。在这个压缩包中,包含了三个核心的jar文件:`quartz-all-...
Spring Quartz定时器是一种在Java应用中实现定时任务的流行框架,它允许开发者精确地调度任务执行。本篇文章将深入探讨如何在Spring框架中简单实现Quartz定时器,并结合源码和工具来帮助理解其工作原理。 首先,让...
本文将详细介绍如何在Spring项目中集成Quartz定时器,并通过一个简单的示例来进行演示。 #### 一、环境准备 为了能够顺利地运行示例代码,我们需要准备以下必要的依赖库: - `jta-1.1.jar`:用于事务管理。 - `...
Spring Quartz 是一个强大的任务调度框架,它允许开发者在Java应用程序中定义定时任务。这个示例提供了在Spring框架中集成Quartz的详细步骤,适合Java工程的实现。下面将详细介绍Spring与Quartz结合使用的相关知识点...
在Spring中集成Quartz,首先需要在项目的类路径下添加这三个jar包,然后通过Spring的配置文件来声明Quartz的相关bean。你可以定义`SchedulerFactoryBean`来创建调度器,`JobDetailBean`来定义作业,以及`...
本篇文章将详细讲解两种在Spring MVC框架中实现定时任务的方法:Spring MVC自带的定时器以及Quartz与Spring的集成。 首先,我们来看看Spring MVC自带的定时任务。Spring MVC作为Spring框架的一个模块,主要处理HTTP...
然后,配置Spring的XML文件来设置定时器。在配置中,你需要定义`JobDetailBean`来指定任务类,并通过`CronTriggerBean`来设定调度规则。例如: ```xml <bean name="userTimelineQuartz" class="org.springframework...
本文将深入探讨如何使用Spring整合Quartz来实现定时器,并提供相关代码示例。 首先,理解Spring框架。Spring是一个开源的Java平台,它提供了全面的企业级应用程序开发解决方案,包括依赖注入(DI)、面向切面编程...
Spring Quartz 是一个集成Quartz定时任务框架的Spring模块,它为开发者提供了在Spring环境中便捷配置和管理定时任务的能力。Quartz作为一个强大且功能丰富的任务调度框架,能够灵活地定义任务的执行时间表,并且可以...
在Java Spring框架中,开发者有多种选择来实现定时任务的功能,其中最为流行的两种方式分别是使用Java自带的`Timer`类以及OpenSymphony的Quartz定时器。本文将重点探讨Quartz定时器的配置与使用,尤其是其时间设置的...
首先,要使用Spring的Quartz定时器,你需要确保引入了以下核心的jar包: 1. `quartz.jar`:这是Quartz的核心库,包含了Quartz的调度器、作业、触发器等核心组件。 2. `spring-context-support.jar`:Spring框架提供...
本文将详细讲解如何在Spring Boot项目中集成Quartz定时器,以及如何利用Spring的依赖注入特性来实现Job。 一、集成Quartz定时器 1. 添加依赖:首先,你需要在Spring Boot项目的`pom.xml`或`build.gradle`文件中...
在Spring应用中添加Quartz支持,你需要在`pom.xml`或`build.gradle`文件中引入Quartz的依赖,比如`quartz-all.jar`。接着,在Spring的配置文件(如`applicationContext.xml`)中,定义一个`SchedulerFactoryBean`来...
作为一个专业的IT行业大师,我很高兴为你解析Quartz定时器的核心概念、功能以及如何通过源码学习。 Quartz定时器允许开发者创建、调度和管理任务,这些任务可以是简单的函数调用或者复杂的业务流程。它支持多种调度...
《Spring与Quartz定时器深度解析》 在Java开发领域,Spring框架因其强大的功能和灵活性而备受推崇。其中,Spring对任务调度的支持是其一大亮点,尤其与Quartz的集成,使得开发者能够方便地实现定时任务。Quartz是一...
本篇将深入探讨如何在Spring中启动和停止Quartz定时器。 首先,我们需要理解Spring和Quartz的基本概念。Spring是一个强大的Java企业级应用开发框架,它提供了依赖注入(DI)和面向切面编程(AOP)等核心特性。而...
让我们深入探讨一下这个"spring2.0+quartz1.6定时器"的工作原理和实现细节。 首先,Spring框架是一个广泛应用的开源Java框架,它提供了依赖注入(Dependency Injection, DI)和面向切面编程(Aspect-Oriented ...