package com.xiewei.soft.text;
		import java.util.TimerTask;
		public class HelloWorldTask extends TimerTask{
  public  void  run (){
   System.out.print("Hello world");
  }
}
package com.xiewei.soft.text;
		import java.io.IOException;
		import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
		public class Fixed {
  public static void main(String[] arg) throws IOException{
   ApplicationContext ctx=new FileSystemXmlApplicationContext("JavaSource/conf/timetask.xml");
   System.in.read();
  }
}
然后在spring配置文件中插入
<beans>
  <bean id ="helloWordTask"  class="com.xiewei.soft.text.HelloWorldTask" />
  <bean id="timerTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
    <property name="delay">
      <value>1000</value>
    </property>
    <property name="period">
      <value>3000</value>
    </property>
    <property name="timerTask">
      <ref local="helloWordTask"/>
    </property>
  </bean>
  <bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">
   <property name="scheduledTimerTasks">
      <list>
      <ref local="timerTask"/>
      </list>
    </property>
  </bean>
</beans>
测试成功!!!!!!!
	posted on 2006-10-31 15:18 
野风 阅读(1513) 
评论(1)  编辑  收藏