【问题标题】:Is there an equivalent to Thread.sleep when dealing with Eclipse Jobs?处理 Eclipse 作业时是否有与 Thread.sleep 等效的方法?
【发布时间】:2010-09-16 10:48:57
【问题描述】:

我正在编写 Eclipse 插件,其中有很多正在运行的作业。

在某些情况下,我希望作业在当前执行点“休眠”一段时间并从该位置继续(而不是重新安排作业并从头开始)。

我的理解是在 Eclipse 作业中使用 Thread.sleep 已被弃用。

是否有可接受的替代方法来完成此操作?

【问题讨论】:

    标签: eclipse scheduling sleep


    【解决方案1】:

    我认为你最好的选择可能是重新安排工作并从你离开的地方继续。比如:

    class MyJob {
      int state;
      IStatus run(IProgressMonitor m) {
        if (state == 0) {
          phase1();
          schedule(1000);
        }
        else if (state == 1) {
          phase2();
        }
        return Status.OK;
      }
      void phase1() {
        state = 1;
      }
      void phase2() {
        state = 2;
      }
    }
    

    【讨论】:

    • 我认为这是正确的做法。工作旨在执行任务并摆脱困境。跟踪状态将为您提供所需的功能。
    • 我有一些异步运行的守护进程和装饰作业,但在某些情况下需要暂停。你所描述的几乎就是我现在正在做的事情,但这会使代码复杂化,我希望有一些我错过的优雅调用......
    猜你喜欢
    • 2010-10-02
    • 1970-01-01
    • 1970-01-01
    • 2017-11-09
    • 2017-10-23
    • 1970-01-01
    • 1970-01-01
    • 2019-01-11
    • 1970-01-01
    相关资源
    最近更新 更多