1

I want to check if a Job has finished. Currently I do this:

 if ( traceJob.getState() != Job.WAITING && traceJob.getState() != Job.RUNNING){

But I think there should be a better way to check. Anyone has any good idea ?

2c00L
  • 495
  • 12
  • 29

2 Answers2

6

You can use Job.addJobChangeListener to add a listener to a Job. The done method of the listener is called when the job finishes. There is a JobChangeAdapter class with default implementations of all the IJobChangeListener methods so that you don't need to implement all of them.

You can use Job.getJobManager().join(family, progress monitor) to wait for a Job to finish. This requires your Job to override the belongsTo method to test which family the Job belongs to. There is also Job.join() to wait for a specific job to finish.

greg-449
  • 109,219
  • 232
  • 102
  • 145
0

There isn't a way to directly check it (because NONE is also returned, before a job is scheduled to run).

You might want to use add a

boolean finished=false to the Job.

it should be false on initialization, set to true as soon as the job finished (somewhere in method done() maybe?)

Bart Hofma
  • 644
  • 5
  • 19