Spring定时器(使用注解)
2015-06-24 16:27
453 查看
先需要在springMVC的配置文件中,配置定时器的扫描注解
定时器的实现代码
最后写个main方法测试下
<!-- 定时器开关 开始--> <task:annotation-driven />
定时器的实现代码
package com.test.control.base; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component public class SpringTimerTest { /** * 启动时执行一次,之后每隔3秒执行一次 */ @Scheduled(fixedRate = 1000 * 3) public void print() { System.out.println("timer running..."); } /** * 定时启动。每天凌晨 16:19 执行一次 */ @Scheduled(cron = "0 19 16 * * *") public void show() { System.out.println("定时器启动..."); } }
最后写个main方法测试下
public static void main(String[] args) { ApplicationContext ctx = new ClassPathXmlApplicationContext("springmvcContext.xml"); }
相关文章推荐
- aix下java程序运行问题
- 我的Java开发学习之旅------>Java经典排序算法之快速排序
- Java作业整理
- Java作业整理
- Struts2+Hibernate4+Spring3 整合登录例子
- Java屏幕截图
- java作业整理
- 没有main的hello world 程序——Java
- 【Java设计模式】三种单例模式
- java作业整理
- 项目搭建系列之三:SpringMVC框架下使用Ehcache对象、数据缓存
- java web中的多条件查询
- svn插件如何关联项目到VisualSVN
- House Robber II LeetCode Java
- spring mvc/ RESTful
- Ehcache 整合Spring 使用页面、对象缓存
- java join用法
- openfire如何整合spring mvc
- JAVA NIO之浅谈内存映射文件原理与DirectMemory
- Mac下面,eclipse配置jre