ITeye博客

spring 定时器(spring3.0)

beyondbn · 2015-04-08 11:50 · Spring · 编程语言 · Markdown

参考文档:http://blog.csdn.net/coooliang/article/details/6265664

cron介绍:
http://www.360doc.com/content/10/0127/14/36589_14507247.shtml

 

用了标签 真的简单好多!!!

 

 

首先要引入xsd:

 

[xhtml] view plaincopyprint?

 

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  3. xmlns:task="http://www.springframework.org/schema/task"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  6. http://www.springframework.org/schema/task
  7. http://www.springframework.org/schema/task/spring-task-3.0.xsd">
  8. <!--
  9. 这里加入了
  10. xmlns:task="http://www.springframework.org/schema/task"
  11. http://www.springframework.org/schema/task
  12. http://www.springframework.org/schema/task/spring-task-3.0.xsd
  13. -->
  14. <task:annotation-driven /> <!-- 定时器开关-->
  15. <bean id="taskTest" class="com.jungle.test.TaskTest"></bean>
  16. <task:scheduled-tasks>
  17. <!--
  18. 这里表示的是从第五秒开始 ,每三秒执行一次 (而不是 三分之五 秒执行一次哦~~)
  19. -->
  20. <task:scheduled ref="taskTest" method="say" cron="5/3 * * * * ?" />
  21. <task:scheduled ref="taskTest" method="hello" cron="5/3 * * * * ?"/>
  22. </task:scheduled-tasks>

 

 

普通java类:

 

 

 

[java] view plaincopyprint?

 

  1. package com.jungle.test;
  2. import java.util.Date;
  3. public class TaskTest {
  4. public void say() {
  5. System.out.println("这个真好用!!!" + new Date());
  6. }
  7. public void hello(){
  8. System.out.println("hello!!!");
  9. }
  10. }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。