项目总结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 ...
随机推荐
- CSS GRID ESSENTIALS
CSS GRID ESSENTIALS Review At this point, we've covered a great deal of different ways to manipulate ...
- ZooKeeper自定义数据日志目录
安装版本:zookeeper-3.4.10 问题描述: ZooKeeper在启动时会将zookeeper.out输出到当前目录,不仅不友好,有时候可能会因为目录权限问题引发一些不必要的麻烦. 脚本分析 ...
- 【371】Twitter 分类相关
Bag-of-words model:就是将句子打散成单词的集合. N-gram model:同上,只是按照 n 进行顺序组合. 参考:机器学习实战教程(四):朴素贝叶斯基础篇之言论过滤器 留言板侮辱 ...
- linux下给PHP安装拓展
要先完成了上一篇文章的phpize的操作,并激活它才能下一步. 下载拓展,在http://pecl.php.net/这个网站下载,其他的有可能不成功,我之前还很纳闷phpize已经调试通过了,但是切换 ...
- DNS泛解析配置
多个域名走同一个nginx代理服务器,多个域名如果有相同的后缀,就可以使用泛解析了,配置如下 编辑文件:/etc/dnsmasq.conf address=/aa.com/172.16.10.10 a ...
- 制作基于U盘启动和网络常识
一.制作基于U盘启动的操作系统盘1.准备相关的软件和硬件 下载软件并安装到[电脑]中 ——大白菜.老毛桃 硬件——U盘(空的) 2.插入U盘,点击桌面上的[大白菜装机版]打开大白菜, 点击[一键制作U ...
- Unity AssetBundle
Unity AssetBundle爬坑手记 - 夜阑卧听风吹雨 时间 2014-09-15 16:55:00 博客园精华区原文 http://www.cnblogs.com/ybgame/p/39 ...
- windows上使用metastore client java api链接hive metastore问题
https://github.com/sdravida/hadoop2.6_Win_x64 下载winutils.exe 添加到path中
- the type java.io.ObjectInputStream cannot be resolved. It is indirectly......
问题的原因: 配置tomcat7.0的时候自己设置了jre的版本1.8,而没有用myeclipse10自带的jre1.6,导致了出现了差错! 两种解决的办法: 1.点击windows--->pr ...
- Mono vs IL2CPP
[Mono vs IL2CPP] 参考:http://blog.csdn.net/gz_huangzl/article/details/52486255