views:

232

answers:

1

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?

+2  A: 

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;
  }
}
Dave Dunkin
I think that this is the right approach. Jobs are designed to perform a task and get out of the way. Keeping track of the state would give you the functionality you're asking for.
AdamC
I have a few daemons and decorating jobs that run asynchronously but that in certain conditions need to pause. What you're describing is pretty much what I'm doing right now, but that complicates the code, I was hoping that there was some elegant call that I was missing...
Uri