Job代表一個異步操作。
          要執行的操作寫在run方法里。

          //定義一個Job
          class AJob extends Job
          {
           
          public AJob()
           
          {
            
          super("Andy's Job");
           }


           
          public IStatus run(IProgressMonitor monitor)
           
          {
            System.out.println(
          "This is Andy's Job");
            
          return Status.OK_STATUS;
           }

          }



          schedule后,任務在平臺線程等待隊列中排隊,等待調度執行。
          調用方式1:

          //異步調用
          AJob job = new AJob();
          job.schedule(); 
          //喚起平臺線程來調度這個Job

          調用方式2:

          //結束后再運行
          AJob job = new AJob();
          job.schedule();
           
          // do some other things.
          job.join();        //block,直到job完成或調用線程被中斷
          if(job.getResult().isOk())
          {
           
          //Job completed with success.
          }

          else
          {
           
          //Job did not complete successfully.
          }


          取消一個Job:
          if(!job.cancel())
          {
           job.join();
          }
           //cancel可能不會立即成功,我們用join等待cancel操作完成。


          版權所有 羅明
          posted on 2005-10-06 15:26 羅明 閱讀(940) 評論(0)  編輯  收藏 所屬分類: Eclipse
           
          主站蜘蛛池模板: 成武县| 平塘县| 皮山县| 大洼县| 合川市| 阜南县| 朝阳市| 屏山县| 皮山县| 上虞市| 垫江县| 堆龙德庆县| 大足县| 雅安市| 延长县| 连州市| 平原县| 万载县| 蛟河市| 虹口区| 汽车| 竹北市| 若尔盖县| 措美县| 郸城县| 民和| 西林县| 南部县| 南和县| 剑川县| 大庆市| 遂溪县| 甘洛县| 右玉县| 淮阳县| 海丰县| 鄢陵县| 长顺县| 错那县| 冕宁县| 柘城县|