处理 Eclipse Jobs 时是否有与 Thread.sleep 等效的方法?

发布于 2024-07-07 05:42:37 字数 183 浏览 4 评论 0原文

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

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

我的理解是,在 Eclipse 作业中使用 Thread.sleep 是相当不推荐的。

有没有可以接受的替代方案来实现这一目标?

I am writing Eclipse plugins where there are quite a few running jobs.

In some cases, I want the job to "sleep" for a while at the current point of execution and continue from that spot (rather than reschedule the job and start it from scratch).

My understanding is that using Thread.sleep within Eclipse jobs is quite deprecated.

Is there an acceptable alternative to accomplishing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一瞬间的火花 2024-07-14 05:42:37

我认为你最好的选择可能是重新安排工作并从上次中断的地方继续。 就像是:

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;
  }
}

I think your best bet may be to reschedule the job and pick up where you left off. Something like:

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;
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文