job
详情见:http://blog.csdn.net/wxwzy738/article/details/25158787
spring.xml
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:p="http://www.springframework.org/schema/p"
- xmlns:task="http://www.springframework.org/schema/task"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
- http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
- http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
- <task:annotation-driven /> <!-- 定时器开关-->
- <bean id="myTaskXml" class="com.spring.task.MyTaskXml"></bean>
- <task:scheduled-tasks>
- <!--
- 这里表示的是每隔五秒执行一次
- -->
- <task:scheduled ref="myTaskXml" method="show" cron="*/5 * * * * ?" />
- <task:scheduled ref="myTaskXml" method="print" cron="*/10 * * * * ?"/>
- </task:scheduled-tasks>
- <!-- 自动扫描的包名 -->
- <context:component-scan base-package="com.spring.task" />
- </beans>
=========================================两种方式:
01:基于注解
利用spring中的以下配置
<task:annotation-driven /> <!-- 定时器开关-->
- <!-- 自动扫描的包名 -->
- <context:component-scan base-package="com.spring.task" />
- 类注解:
- @Component
- 方法注解:
- @Scheduled(cron = "0 0 1 * * *")
----------------------------------------------------------------------------------
- package com.spring.task;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Component;
- /**
- * 基于注解的定时器
- * @author hj
- */
- @Component
- public class MyTaskAnnotation {
- /**
- * 定时计算。每天凌晨 01:00 执行一次
- */
- @Scheduled(cron = "0 0 1 * * *")
- public void show(){
- System.out.println("Annotation:is show run");
- }
- /**
- * 心跳更新。启动时执行一次,之后每隔2秒执行一次
- */
- @Scheduled(fixedRate = 1000*2)
- public void print(){
- System.out.println("Annotation:print run");
- }
- }
02:基于xml
利用spring中的以下配置
- <task:scheduled-tasks>
- <!--
- 这里表示的是每隔五秒执行一次
- -->
- <task:scheduled ref="myTaskXml" method="show" cron="*/5 * * * * ?" />
- <task:scheduled ref="myTaskXml" method="print" cron="*/10 * * * * ?"/>
- </task:scheduled-tasks>
- package com.spring.task;
- /**
- * 基于xml的定时器
- * @author hj
- */
- public class MyTaskXml {
- public void show(){
- System.out.println("XMl:is show run");
- }
- public void print(){
- System.out.println("XMl:print run");
- }
- }
随机推荐
- SQL21日自学通笔记(1)
查找不重复数据 DISTINCT 查询日期 在access中格式是yyyy-mm-dd,Query执行的语句中用‘#’+Formatdata(‘yyyy-mm-dd’,date)+‘#’ SQL运算符 ...
- 标签案例-开发foreach标签
if(item.getClass().isArray()){ this.collection = new ArrayList(); int length = Array.getLength(items ...
- MongoDB的配置、启动、关闭
MongoDB 是一个基于分布式文件存储的数据库.由 C++ 语言编写.旨在为 WEB 应用提供可扩展的高性能数据存储解决方案. MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系 ...
- KnockoutJS:
一.ko对象 js对象的改变都会导致viewmodel的变化,但view不一定变化 往ko对象里面push,viewmodel的变化,引起view的变化. 往js对象里面push,model的变化引起 ...
- Java将文件转为字节数组
Java将文件转为字节数组 关键字:文件,文件流,字节流,字节数组,二进制 摘要:最近工作中碰到的需求是,利用http传输二进制数据到服务器对应接口,需要传输userId, file(加密后)等一系列 ...
- JavaScript + PHP 实现刷新继续保持倒计时的按钮
场景:发送一个验证码到手机,当验证码发出时,会提示隔 1 分钟之后可以再次发送.通常有这几种方式防止恶意请求,一是再次发送之前需要输入验证码,二是在指定的时间间隔之内不能再次发送. 有些网站在 1 分 ...
- vpn
https://itunes.apple.com/us/app/sonicwall-mobile-connect/id822514576?mt=12
- Tiddlywiki 维基程序使用手册
文档 http://tiddlywiki.com/ http://web.nlhs.tyc.edu.tw/~lss/wiki/TiddlyWikiTutorialTW.html https://sit ...
- MySQL运行状态show status详解
状态名 作用域 详细解释 Aborted_clients Global 由于客户端没有正确关闭连接导致客户端终止而中断的连接数 Aborted_connects Global 试图连接到MySQL服务 ...
- 使用git@osc管理现有项目
首先安装git和powershell集成git工具 参考 http://www.cnblogs.com/kreo/p/4685988.html 打开windows powershell,进入项目目录, ...