您的位置:首页 > 编程语言 > Java开发

在Spring3中使用注解(@Scheduled)创建计划任务(最简化配置)

2016-06-22 14:57 573 查看
一、配置文件

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

再加入:

<task:annotation-driven/>  

二、java

package com.springmvc.tesk;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class SpringTaskDemo {

@Scheduled(fixedDelay = 5000)
void doSomethingWithDelay(){
System.out.println("I'm doing with delay now!");
}

@Scheduled(fixedRate = 5000)
void doSomethingWithRate(){
System.out.println("I'm doing with rate now!");
}

@Scheduled(cron = "0/5 * * * * *")
void doSomethingWith(){
System.out.println("I'm doing with cron now!");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: