问题
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 ?
回答1:
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.
回答2:
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?)
来源:https://stackoverflow.com/questions/26848719/eclipse-rcp-check-if-a-job-has-finished