Tuesday, January 13, 2015

Eclipse Jobs API : Perform something when job is done

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





5 Strategies for Getting More Work Done in Less Time

Summary.    You’ve got more to do than could possibly get done with your current work style. You’ve prioritized. You’ve planned. You’ve dele...