Spring目前支持以注解的形式执行定时、周期任务,实现起来非常方便!!
<span style="font-size:18px;"><context:component-scan base-package="com.xx.xx.schedule"/></span>
@configuration
@EnableScheduling
@Scheduled
class代码如下:
将每5秒打印出当前时间
<span style="font-size:18px;">@Configuration @EnableScheduling public class SpringScheduleTest { @Scheduled(cron = "*/5 * * * * *") // @Scheduled(fixedDelay = 5000) public void doTask(){ System.out.println("Now is :" + new Date()); } }</span>
原文地址:http://blog.csdn.net/aqzwss/article/details/44222243