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");
- }
- }
随机推荐
- php多线程详解
在说明多线程的题前,需要弄清楚以下几个问题 1,ts 和 nts的区别 Thread Safe和NoneThread Safe 先说windows的,在php官网,在windows区域有在文件下在有 ...
- Thread-Safe Resource Manager
http://php.net/manual/en/internals2.memory.tsrm.php When PHP is built with Thread Safety enabled, th ...
- 深入理解ANGULARUI路由_UI-ROUTER
最近在用 ionic写个webapp 看到几个demo中路由有好几种,搞的有点晕,查下资料研究下,做个笔记,其中大部分为摘抄别人的,做个说明免得被人吐槽. Angularjs ui-router - ...
- argparse解析参数模块
一.简介: argparse是python用于解析命令行参数和选项的标准模块,用于代替已经过时的optparse模块.argparse模块的作用是用于解析命令行参数,例如python parseTes ...
- ruby -检查数据类型
HashObj={","language"=>"zh","make"=>"Apple"," ...
- Creating Signing Identities 生成签名标识
Before you can code sign your app, you create your development certificate and later, a distribution ...
- Windows Server 2008 R2组策略创建用户桌面快捷方式
问题: 如何让所有域用户桌面有一个公司共享的快捷方式,让所有域用户直接双击就能打开公司共享. 解决办法: 1.创建一个zhuyu组织单元 ----- 在zhuyu组织单元创建一个域用户user1. 2 ...
- 安装redis
第一步 下载 第二步 解压 .tar.gz 第三步 make cd redis- make 第四步 启动试一下 src/redis-server 好了 :C Jan ::13.501 # Warni ...
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.0 版本新增序列管理
欲了解V3.0版本的相关内容可查看下面的链接地址. RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.0 版本发布 在V3.0版本的Web(Mvc.WebForm)与WinF ...
- DataTable 转 List<T>
最近在做一个项目,表的数据巨多,而且表的字段一般都在30个以上.公司规定不能用Nhibernate以及ef等ORM框架. 所以查询绑定时的工作量极为痛苦.没有办法,自己写了个DataTableToLi ...