SpringMVC基于注解方式的quartz
项目框架: SpringMVC、MyBatis、JSP
1. 首先配置spring.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"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd"> <!-- 注解定时任务 -->
<task:annotation-driven/>
2. 配置定时任务类
@Component
public class MessageSendService { /**
* 记录日志类
*/
public Log logger = LogFactory.getLog(this.getClass()); /**
* 定时任务方法
*/
@Scheduled(cron = "0/10 * * * * ? ")
public void send(){
logger.info("start.....");
} }
@Component 注解是让Spring可以扫描到并初始化,第一步的配置就是做这个用的
@Scheduled 注解是配置定时任务的执行时间,上面的配置是让定时任务每10执行一次send()方法
3. 实际的项目中定时任务的执行时间可能要在配置文件中配置,就需要用到另一个注解 @PropertySource
@Component
@PropertySource(value="classpath:application.properties")
public class MessageSendService { /**
* 记录日志类
*/
public Log logger = LogFactory.getLog(this.getClass()); /**
* 方法
*/
@Scheduled(cron = "${jobs.message}")
public void send(){
logger.info("start....."); } }
@PropertySource 指定配置文件的位置,和配置文件的名称
@Scheduled 注解做相应的修改
4. application.properties 文件配置
## 轮询时间配置
jobs.message=0/10 * * * * ?
这个定时任务时间配置和linux的crontab差不多
5. Scheduled 参数1
@Scheduled(fixedDelay = 5000)
public void doSomething() {
// something that should execute periodically
}
这个方法将以一个固定延迟时间5秒钟调用一次执行,这个周期是以上一个调用任务的完成时间为基准,在上一个任务完成之后,5s后再次执行
当方法执行超过5秒,下一个轮询发现有正在执行的方法,直接跳过
6. Scheduled 参数2
@Scheduled(fixedRate = 5000)
public void doSomething() {
// something that should execute periodically
}
这个方法将以一个固定速率5s来调用一次执行,这个周期是以上一个任务开始时间为基准,从上一任务开始执行后5s再次调用
当方法执行时间超过5秒,下一个轮询会阻塞,上一个任务执行完成,立即执行此次轮询方法
SpringMVC基于注解方式的quartz的更多相关文章
- SpringMVC入门(基于注解方式实现)
---------------------siwuxie095 SpringMVC 入门(基于注解方式实现) SpringMVC ...
- 04springMVC结构,mvc模式,spring-mvc流程,spring-mvc的第一个例子,三种handlerMapping,几种控制器,springmvc基于注解的开发,文件上传,拦截器,s
1. Spring-mvc介绍 1.1市面上流行的框架 Struts2(比较多) Springmvc(比较多而且属于上升的趋势) Struts1(即将被淘汰) 其他 1.2 spring-mv ...
- springMVC基于注解的控制器
springMVC基于注解的控制器 springMVC基于注解的控制器的优点有两个: 1.控制器可以处理多个动作,这就允许将相关操作写在一个类中. 2.控制器的请求映射不需要存储在配置文件中.使用re ...
- Shiro入门之二 --------基于注解方式的权限控制与Ehcache缓存
一 基于注解方式的权限控制 首先, 在spring配置文件applicationContext.xml中配置自动代理和切面 <!-- 8配置自动代理 --> <bean cl ...
- Elasticsearch-mapper 基于注解方式生成mapping(2.0以上)
Elasticsearch生成mapping的方式上有多种方式,我们可以把mapping做成配置文件,也可以用spring-data-elasticsearch基于注解生成. 在基于注解生成这种方式上 ...
- Spring声明式事务管理(基于注解方式实现)
----------------------siwuxie095 Spring 声明式事务管理(基于注解方式实现) 以转 ...
- SpringMVC的注解方式
mvc-servlet.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=&qu ...
- Spring boot 基于注解方式配置datasource
Spring boot 基于注解方式配置datasource 编辑 Xml配置 我们先来回顾下,使用xml配置数据源. 步骤: 先加载数据库相关配置文件; 配置数据源; 配置sqlSessionF ...
- 缓存初解(五)---SpringMVC基于注解的缓存配置--web应用实例
之前为大家介绍了如何使用spring注解来进行缓存配置 (EHCache 和 OSCache)的简单的例子,详见 Spring基于注解的缓存配置--EHCache AND OSCache 现在介绍一下 ...
随机推荐
- windows下安装google protocbuf
首先安装setuptools: windows:======== 1.下载 ez_setup.py,安装setuptoolshttps://bitbucket.org/pypa/setuptools/ ...
- 解决IOS7在TableView 被导航栏挡住的BUG!!
self.edgesForExtendedLayout = UIRectEdgeNone; 就这么简单!
- Flume简介及使用
一.Flume概述 1)官网地址 http://flume.apache.org/ 2)日志采集工具 Flume是一种分布式,可靠且可用的服务,用于有效地收集,聚合和移动大量日志数据.它具有基于流数据 ...
- python类可以任意添加属性
python类可以任意添加属性 class A(object): def __init__(self): self.name = "zhangsan" self.age = 18 ...
- mysql union (all) 后order by的排序失效问题解决
上sql select * FROM ( SELECT SUM(c.overtime_num) AS delay_num, ) rate , '全网' as reaCodeFROM calc_vmap ...
- ambari关于ranger的一个大坑----端口永远是3306,需要手动修改
ambari关于ranger的一个大坑----端口永远是3306 这个坑是我在搭建ambari环境的时候发现的,我并没有找到原因,求助同事,然后一步步循着蛛丝马迹和试探,终于解决了,然而也揭露了amb ...
- matplotlib中的legend()—显示图例
源自 matplotlib中的legend()——用于显示图例 -- 博客园 http://www.cnblogs.com/yinheyi/p/6792120.html legend()的一个用法: ...
- (二)无状态的web应用(单py的Django占位图片服务器)
本文为作者原创,转载请注明出处(http://www.cnblogs.com/mar-q/)by 负赑屃 阅读本文建议了解Django框架的基本工作流程,了解WSGI应用,如果对以上不是很清楚,建议结 ...
- 08 网络配置、shh服务、bash命令和元字符
作业一:完成作业未做完的集群架构作业二:临时配置网络(ip,网关,dns)+永久配置 作业三:为集群内的机器设定主机名,利用/etc/hosts文件来解析自己的集群中所有的主机名,相应的,集群的配置应 ...
- 82. Remove Duplicates from Sorted List II(删除有序链表中的重复元素)
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...