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

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

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


          網站導航:
           
          主站蜘蛛池模板: 平陆县| 体育| 连云港市| 克什克腾旗| 晋城| 保康县| 乐安县| 达州市| 鹤岗市| 田林县| 社旗县| 资源县| 张家港市| 长春市| 丹寨县| 西峡县| 壶关县| 县级市| 行唐县| 东乌| 唐山市| 安康市| 利川市| 社会| 双辽市| 崇州市| 莎车县| 探索| 闸北区| 莆田市| 蓝山县| 宜宾市| 南岸区| 永仁县| 筠连县| 南召县| 安陆市| 全南县| 宝应县| 石河子市| 斗六市|