首页 > 代码库 > Spring @Scheduled
Spring @Scheduled
Spring @Scheduled是Spring计划任务的一种很简洁的实现。用来替代Quartz的方案。
要使用此特性,需要Spring3.2以上版本。用法:
1、在xml的配置中,需要加入:
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.2.xsd"
2、写一个简单例子:
import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.text.SimpleDateFormat; import java.util.Date; /** * Created by leizhimin on 2014/8/16. * * @author leizhimin 2014/8/16 17:46 */ @Component @Lazy(false) public class TestJob { public static SimpleDateFormat sdf_yyyyMMddHHmmss = new SimpleDateFormat("yyyyMMddHHmmss"); @Scheduled(cron = "0/5 * * * * ?") public void exejob() { System.out.println(sdf_yyyyMMddHHmmss.format(new Date()) + " :执行中。。。"); } }
每隔5秒中就会输出一条信息。
本文出自 “熔 岩” 博客,请务必保留此出处http://lavasoft.blog.51cto.com/62575/1541841
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。