随笔-6  评论-3  文章-0  trackbacks-0

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 野风 阅读(1495) 评论(1)  编辑  收藏

评论:
# re: spring中的定时器 2006-12-18 11:48 | j2eesun
您好
我正在用spring做一个定时器
你可以把完整的代码发给我一份吗
谢谢
邮箱:j2eesun@163.com  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: