When we need to do something for example notify user or cleaup someting after a JOB is finished we can user the JobChangeListener to accomplish this. see the folowing code:
final Job job = new Job("Long Running Job") { protected IStatus run(IProgressMonitor monitor) { try { while(hasMoreWorkToDo()) { // do some work // ... if (monitor.isCanceled()) return Status.CANCEL_STATUS; } return Status.OK_STATUS; } finally { schedule(60000); // start again in an hour } } }; job.addJobChangeListener(new JobChangeAdapter() { public void done(IJobChangeEvent event) { if (event.getResult().isOK()) postMessage("Job completed successfully"); else postError("Job did not complete successfully"); } }); job.setSystem(true); job.schedule(); // start as soon as possible
See the details in following website:
https://eclipse.org/articles/Article-Concurrency/jobs-api.html
No comments:
Post a Comment