Spring Task定时任务Scheduled
2015-08-29 16:19
543 查看
Spring的任务调度,采用注解的形式
Spring中@Scheduled的用法。
spring的配置文件如下,先扫描到任务的类,打开spirng任务的标签
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:task="http://www.springframework.org/schema/task" -------------------- xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"> <!-- 扫描controller --> <context:component-scan base-package="com.springmvc.controller" /> <task:annotation-driven/>
Spring的任务类HelloJobController
package com.springmvc.controller; import java.util.Date; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component public class HelloJobController { @Scheduled(cron = "*/5 * * * * ?") //@Scheduled(fixedDelay = 5000) public void demoServiceMethod() { System.out.println("Method executed at every 5 seconds. Current time is :: " + (new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date())); } }
运行结果
![](https://images2015.cnblogs.com/blog/801359/201508/801359-20150829153642281-230251347.png)
scheduling
task-scheduling-simplifications-in-spring-3-0
相关文章推荐
- 解决spring的dubbo配置文件报错解决思路
- Java中常用的集合
- Spring学习笔记之一----基于XML的Spring IOC配置
- Spring学习笔记之二----基于XML的Spring AOP配置
- JVM、JRE、JDK的关系浅析
- java内存泄漏查找
- 关于spring依赖注入的一个知识点
- Java暗箱操作之自动装箱与拆箱
- Java集合set集合介绍
- Eclipse配置GitHub代码库(以Windows7为例)
- JavaEE中用response向客户端输出中文数据乱码问题分析
- Java数组实现循环队列的两种方法
- RSA非对称加密,使用OpenSSL生成证书,iOS加密,java解密
- DesignPattern_Java:Adapter Pattern
- java 基础之notice
- 【软考】——Java环境配置
- Dijkstra算法求最短路径(java)
- eclipse git 配置 远程上传按钮无法使用问题
- The Java EE 6 Tutorial Writing Service Methods
- Java中的内部类