spring3使用task注记及task:annotation-driven解决定时问题
来源:互联网 发布:debian修改软件源 编辑:程序博客网 时间:2024/05/27 14:13
定义一个定时操作
package com.jCuckoo.demo;import java.text.SimpleDateFormat;import java.util.Date;import org.springframework.scheduling.annotation.Scheduled;public class Singer {//@Scheduled(fixedDelay=1000) //第一种方式//fixedDelay延时多少毫秒,多少毫秒执行一次@Scheduled(cron="0 * * * * *") //第二种方式/*1 Seconds (0-59)2 Minutes (0-59)3 Hours (0-23)4 Day of month (1-31)5 Month (1-12 or JAN-DEC)6 Day of week (1-7 or SUN-SAT)7 Year (1970-2099)取值:可以是单个值,如6;也可以是个范围,如9-12;也可以是个列表,如9,11,13也可以是任意取值,使用**///0 * * * * * 代表每分钟执行一次/* 2011-09-07 09:23:002011-09-07 09:24:002011-09-07 09:25:002011-09-07 09:26:00 */public void singing(){Date date=new Date();SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");System.out.println(sdf.format(date));}}
spring配置文件如下:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.0.xsdhttp://www.springframework.org/schema/taskhttp://www.springframework.org/schema/task/spring-task-3.0.xsd"><bean id="singer" class="com.jCuckoo.demo.Singer"/><task:annotation-driven /></beans>
测试类
package com.jCuckoo.demo;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class MainTest {public static void main(String[] args) {ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");Singer singer=(Singer) context.getBean("singer");}}
结果:
2011-09-07 09:23:00
2011-09-07 09:24:00
2011-09-07 09:25:00
2011-09-07 09:26:00
- spring3使用task注记及task:annotation-driven解决定时问题
- spring3使用task注记及task:annotation-driven解决定时问题
- spring3使用task注记及task:annotation-driven解决定时问题
- spring3使用task注记及task:annotation-driven解决定时问题
- spring3使用task注记及task:annotation-driven解决定时问题
- Spring注解配置定时任务<task:annotation-driven/>
- Spring注解配置定时任务<task:annotation-driven/>
- Spring注解配置定时任务<task:annotation-driven/>
- Spring注解配置定时任务<task:annotation-driven/>
- Insight task:annotation-driven 解析 | Insight 常识
- 关于Spring中的<task:annotation-driven/>配置
- spring使用<mvc:annotation-driven/>来解决定时任务
- Spring3.0.6定时任务task:scheduled
- Spring3.0.6定时任务task:scheduled
- Spring3.0.6定时任务task:scheduled
- Spring3.0.6定时任务task:scheduled
- Spring3.0.6定时任务task:scheduled
- Spring3.0.6定时任务task:scheduled
- Box2D中的b2DebugDraw使用示例
- ubuntu开启telnet服务
- 用java.util.Timer定时执行任务
- PHP的BC Math
- 高效程序员的45个习惯:项目leader之路
- spring3使用task注记及task:annotation-driven解决定时问题
- 记录Java代码的执行时间
- 外链
- 【java锁机制Synchronized】是这样吗?
- 2011-09-07[sqlserver投票统计查询问题]
- 给予者型(ENFJ)的综合描述
- Java Timer定制每天特定时间执行任务
- hdu 1012 u Calculate (水)
- 数据库关系图