执行定时业务one
spring执行定时任务
定义一个任务是很简单的实现TimerTask的run方法就可以了.
如下:SayHelloTask.java
1package test.timerTask; 2 3import java.util.TimerTask; 4 5public class Task extends TimerTask { 6 7 @Override 8 public void run() { 9 // TODO Auto-generated method stub10 System.out.println("测试TimerTask : Hello !!");11 }1213} 1package test.springTimer; 2 3import java.util.TimerTask; 4 5public class Task2 extends TimerTask{ 6 public void run(){ 7 8 System.out.println("task2 is running"); 9 }1011 12}13然后是配置文件: <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans><bean id="sayHelloTask" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><bean id="sayHelloJob" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"><property name="triggers"><ref bean="helloCronTrigger"/></property></bean> </beans>