- 浏览: 59489 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
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 958一个Cron-表达式是一 ... -
spring多个定时任务job.xml配置
2011-01-17 10:26 1209<?xml version="1.0" ... -
c3p0在spring下的配置过程
2010-12-03 18:14 870(1) 在hibernate.properties中添加: ... -
c3p0在spring的配置(详解)
2010-12-03 18:13 764C3P0是一个开放源代码的 ... -
Xmemcached使用之与Spring整合
2010-12-03 18:12 13221 简介Xmemcached是一个高性能的基于java n ... -
Spring中Quartz的配置
2010-12-03 18:11 657各种企业应用几乎都会碰到任务调度的需求,就拿论坛来说:每隔半个 ...
相关推荐
Spring Quartz 定时器示例(Web工程版),欢迎下载。
Spring Quartz 定时器示例(Java工程版),欢迎下载。
Spring中的Quartz配置-Spring-定时器-java定时器.doc
Spring Quartz定时器 Spring Quartz定时器 Spring Quartz定时器 Spring Quartz定时器
quartz-all-1.6.0.jar commons-dbcp-1.2.1.jar commons-pool.jar 三个jar包,用于Spring Quartz定时器
我自己亲自测试过的例子,spring quartz定时器的简单配置和使用,保证成功运行
SpringQuartz定时器的配置[参照].pdf
SpringQuartz定时器的配置[归类].pdf
spring定时器 quartz支持的3个jar包 quartz-all-1.8.4.jar slf4j-api-1.5.3.jar slf4j-simple-1.5.3.jar
Spring-quartz实现定时器(含代码)
这里有spring的quartz定时器要用到的jar包,本人也有自己的小demo,如需要请联系本人
spring boot集成quartz定时器,job支持spring的依赖注入
配置Spring+quartz定时器
NULL 博文链接:https://penghuaiyi.iteye.com/blog/649561
定时器的配置文件(两种方式:springmvc自带定时,Quartz与spring结合的定时)
spring定时器代码。解决多次执行问题。包含quartz-all.jar包。 说明很详细。希望能帮上哪位朋友。
spring2.0+quartz1.6写的一个定时器,能运行的
spring定时器Spring定时器的两种实现方式Java的Timer类和OpenSymphony的Quartz。
java Spring OpenSymphony的Quartz定时器的时间设置
spring和quartz的定时器的启动和停止例子