マルチスレッドのRunnableインタフェース

パッケージcom.sdwlf.job.entInfo.service;

輸入org.springframework.context.ApplicationContext;
輸入org.springframework.web.context.ContextLoaderListener。
輸入com.freework.base.exception.AppException。

パブリッククラスEntInfoRunnableはRunnableを実装{

  パブリック静的ApplicationContextのコンテキスト= NULLを、

  プライベート文字列のstartTime;

  プライベート文字列endTimeは、

  公共EntInfoRunnable(文字列のstartTime、endTimeは列){
    this.startTime =たstartTime。
    this.endTimeはendTimeのを=。
  }

  パブリック文字列またgetStartTime(){
    たstartTimeを返します。
  }

  公共ボイドsetStartTime(文字列のstartTime){
    this.startTime =たstartTime。
  }

  パブリック文字列getEndTime(){
    たendTimeを返します。
  }

  公共ボイドsetEndTime(文字列endTimeは){
    this.endTime =たendTime。
  }

 


  @Override
  公共ボイドラン(){

    JobEntInfoServiceサービス=(JobEntInfoService)this.getInstance( "com.sdwlf.job.entInfo.service.JobEntInfoService")。
    {試す
      のThread.sleep(1000);
      System.out.println(のstartTime +」「+ endTimeは)。
      service.synAndDealData(のstartTime、endTimeは)。
    }キャッチ(InterruptedExceptionある電子){
      e.printStackTrace();
    }キャッチ(AppException電子){
      e.printStackTrace();
    }
  }

  パブリック静的オブジェクトのgetInstance(文字列serviceNameを){
    //直接从配置文件中注入サービス类
    場合(ヌル==コンテキスト){
      コンテキスト= ContextLoaderListener.getCurrentWebApplicationContext()。
    }

    context.getBean(serviceNameを)を返します。
  }
}


//具体调用
EntInfoRunnable E =新しいEntInfoRunnable(date.getStartDate()、date.getEndDate());
新しいスレッド(E).start();

おすすめ

転載: www.cnblogs.com/sunshijia1993/p/11318948.html