Eclipse RCP: check if a job has finished

孤街浪徒 提交于 2021-01-28 11:53:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!