Springmvc @Scheduled定时器配置

Springmvc @Scheduled定时器配置

1.在servlet.xml配置文件中配置

    xmlns:task="http://www.springframework.org/schema/task"
 xsi:schemaLocation="
		   http://www.springframework.org/schema/task 
           http://www.springframework.org/schema/task/spring-task-4.1.xsd"
       default-autowire="byName">
         

2.创建自定义定时器类,增加@Component注解

@Component
public class TaskSchedule {@Scheduled(cron="0/20 * * * * ?")   //每20秒执行一次
public void planTask() {
	System.out.println("测试定时任务start");
	long times = System.currentTimeMillis();
System.out.println("测试定时任务end!,用时:"+   (System.currentTimeMillis()-times)+"毫秒");
}}

你可能感兴趣的:(spring)