`
beyondbn
  • 浏览: 71466 次
社区版块
存档分类
最新评论

spring 定时器(spring3.0)

阅读更多

参考文档: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.   
  11. 这里加入了  
  12. xmlns:task="http://www.springframework.org/schema/task"  
  13. http://www.springframework.org/schema/task   
  14.     http://www.springframework.org/schema/task/spring-task-3.0.xsd  
  15.   
  16. -->  
  17.   
  18. <task:annotation-driven /> <!-- 定时器开关-->  
  19.   
  20.   
  21.     <bean id="taskTest" class="com.jungle.test.TaskTest"></bean>  
  22.   
  23.     <task:scheduled-tasks>  
  24.         <!--  
  25. 这里表示的是从第五秒开始 ,每三秒执行一次 (而不是 三分之五 秒执行一次哦~~)  
  26. -->  
  27.         <task:scheduled ref="taskTest" method="say" cron="5/3 * * * * ?" />  
  28.         <task:scheduled ref="taskTest" method="hello" cron="5/3 * * * * ?"/>  
  29.     </task:scheduled-tasks>  

 

 

普通java类:

 

 

 

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

相关推荐

Global site tag (gtag.js) - Google Analytics