项目总结08:spring quartz 定时器Demo
将定时器用到的quartz.jar放在lip文件下

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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<!--映射-->
<bean id= "TimedTask" class ="com.blue.yanxishe.service.timer.TimedTask"/>
<!--自动推送跟踪日志3天未跟新提醒-->
<bean id="autoTailLogRemind" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="TimedTask"/>
<property name="targetMethod" value="autoTailLogRemind"/>
</bean>
<bean id="autoTailLogRemindTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="autoTailLogRemind"/>
<property name="cronExpression" value="0 0 0 * * ?"/>
</bean>
<!--自动推送排期逾期提醒-->
<bean id="autoScheduOverdueRemind" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> //定义JobDetail,即定时任务
<property name="targetObject" ref="TimedTask"/> //目标类是TimeTask
<property name="targetMethod" value="autoScheduOverdueRemind"/> //目标方法时TimeTask类下的autoScheduOverueRemind方法
</bean>
<bean id="autoScheduOverdueRemindTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> //配置触发条件
<property name="jobDetail" ref="autoScheduOverdueRemind"/> //关联需要执行的任务
<property name="cronExpression" value="0 0 0 * * ?"/> //设置定义条件,这里"0 0 0 * * ?",表示每天00:00执行一次
</bean> <!-- 启动触发器的配置开始-->
<bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="autoTailLogRemindTrigger" /> //关联需要执行的任务设置
<ref bean="autoScheduOverdueRemindTrigger" />
</list>
</property>
</bean>
</beans>
web.xml(部分)
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/context.xml
classpath:spring/context-shiro.xml
classpath:spring/context-redis.xml
classpath:spring/quartz.xml
</param-value>
</context-param>
TimedTask.java(完整)
package com.blue.yanxishe.service.timer; import java.io.Serializable; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.blue.common.exception.ServerSqlErrorException;
import com.blue.yanxishe.service.shop.ShopMessageService; @Service
public class TimedTask implements Serializable{ @Autowired
private ShopMessageService shopMessageService; public void autoTailLogRemind() throws ServerSqlErrorException{
shopMessageService.getTailLogRemind();
System.out.println(" getTailLogRemind() was running!!");
} public void autoScheduOverdueRemind() throws ServerSqlErrorException{
shopMessageService.getScheduOverdueRemind();
System.out.println(" getScheduOverdueRemind() was running!!");
}
}
项目总结08:spring quartz 定时器Demo的更多相关文章
- 启用Spring quartz定时器,导致tomcat服务器自动停止
在项目中添加了一个定时功能,基于Spring quartz: 设置好执行时间后(如:每天14:00) 当程序执行完后,就会出现以下信息: 2013-7-22 11:36:02 org.apache.c ...
- Spring Quartz定时器 配置文件详解
在JavaEE系统中,我们会经常用到定时任务,比如每天凌晨生成前天报表,每一小时生成汇总数据等等.我们可以使用java.util.Timer结合java.util.TimerTask来完成这项工作,但 ...
- spring quartz 定时器时间格式设置
"0/10 * * * * ?" 10秒执行一次 "0 0 12 * * ?"每天中午十二点触发"0 15 10 ? * *"每天早上10: ...
- 关于Spring的Quartz定时器设定
在实际的开发业务中经常会遇到定时执行某个任务,如果项目使用的ssh框架的话,就需要配合spring来使用定时器.spring的定时器是一个固定的配置格式,具体的applicationContext配置 ...
- spring启动quartz定时器
在很多中经常要用到定时任务,quartz是定时器中比较好用的,在Spring中使用quartz是很容易的事情,首先在spring的applicationContext.xml文件中增加如下配置: &l ...
- Spring+quartz集群解决多服务器部署定时器重复执行的问题
一.问题描述 Spring自带的Task虽然能很好使用定时任务,只需要做些简单的配置就可以了.不过如果部署在多台服务器上的时候,这样定时任务会在每台服务器都会执行,造成重复执行. 二.解决方案 Spr ...
- Spring的quartz定时器同一时刻重复执行二次的问题解决
最近用Spring的quartz定时器的时候,发现到时间后,任务总是重复执行两次,在tomcat或jboss下都如此. 打印出他们的hashcode,发现是不一样的,也就是说,在web容器启动的时候, ...
- java定时器,Spring定时器和Quartz定时器
一.java定时器的应用 其实java很早就有解决定时器任务的方法了,java提供了了类java.util.TimerTask类基于线程的方式来实现定时任务的操作,然后再提供java.util.Tim ...
- java Quartz定时器任务与Spring task定时的几种实现,
java Quartz定时器任务与Spring task定时的几种实现 基于java 的定时任务实现, Quartz 时间详细配置 请查阅 http://www.cnblogs.com/si ...
随机推荐
- day37-常见内置模块六(其他模块)
其他内置模块 1.subprocess(系统交互)模块 2.math模块 3.zipfile模块 4.keyword模块 5....
- Win2008R2配置WebDeploy(转)
一.配置服务器 1.安装管理服务 2.点击管理服务进行配置 3.安装WebDeploy 3.1通过离线安装包方式安装: https://www.iis.net/downloads/microsoft/ ...
- java 中AIO,BIO,NIO的区别(茅塞顿开)
看到知乎上一篇回答,解决了疑惑:https://www.zhihu.com/question/56673416 第三位作者的回答...原谅我没有登录知乎,不然一定给他留赞. 也可以参考:https:/ ...
- 尚硅谷springboot学习9-配置文件值注入
首先让我想到的是spring的依赖注入,这里我们可以将yaml或者properties配置文件中的值注入到java bean中 配置文件 person: lastName: hello age: 18 ...
- 解析swf文件头,获取flash的原始尺寸
要想解析swf文件头,首先要弄清楚的当然是swf文件格式规范.规范中对swf文件格式作了详细的说明.关于swf文件头,它是由以下几个部分组成:+-------+---+--------+------- ...
- Haskell语言学习笔记(71)Semigroup
Semigroup class Semigroup a where (<>) :: a -> a -> a sconcat :: NonEmpty a -> a stim ...
- numpy-Randow
Randow使用 http://blog.csdn.net/pipisorry/article/details/39508417 概率相关使用 转:http://www.cnblogs.com/Nau ...
- eval 用法
计算 eval('1+1') # 2 在字典中提取键 的值 eval('a',{'a':1}) # 1 计算 Boolean 值 eval( 'True',{'a':1}) # True eval(' ...
- 吴裕雄 06-MySQL选择数据库
实例以下实例选取了数据库 RUNOOB:use RUNOOB;注意:所有的数据库名,表名,表字段都是区分大小写的.所以你在使用SQL命令时需要输入正确的名称. 使用PHP脚本选择MySQL数据库PHP ...
- python进行爬虫
使用python进行网络爬虫 非结构画数据 转为 结构化数据.需要借助ETL(数据抽取,转换,存储)进行. 非结构化数据蕴含着丰富的价值.需要借助ETL进行转换成结构化数据,才能变成有价值的数据.比如 ...