隨筆-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 野風 閱讀(1506) 評論(1)  編輯  收藏

          評論:
          # re: spring中的定時器 2006-12-18 11:48 | j2eesun
          您好
          我正在用spring做一個定時器
          你可以把完整的代碼發給我一份嗎
          謝謝
          郵箱:j2eesun@163.com  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 兴山县| 孝昌县| 永宁县| 固镇县| 周口市| 正镶白旗| 麦盖提县| 文昌市| 饶阳县| 绥阳县| 黔南| 新巴尔虎左旗| 霍州市| 三河市| 大冶市| 上思县| 永川市| 察隅县| 台南市| 天气| 灵台县| 越西县| 庆云县| 大庆市| 无极县| 乐都县| 鄱阳县| 双鸭山市| 格尔木市| 五大连池市| 西青区| 九江县| 太原市| 即墨市| 肃宁县| 大宁县| 鸡东县| 青冈县| 定南县| 巢湖市| 仙桃市|