Jan 14 2009
Using Eclipse Jobs API
Eclipse platform offers great API for managing long running operations in the background. Besides the API for starting, stopping and monitoring progress of the Job – there is also standard UI for managing all those operations. I’m going to present sample usage of Jobs API in you own plug-in/application.
Creating and scheduling Job may look like this:
TrainJob job = new TrainJob(TRAIN_JOB_NAME + file.getName(), classifier); job.setRule(file); job.setUser(true); job.setPriority(Job.SHORT); job.schedule(); // start as soon as possible
Sample of custom Job:
package pl.edu.agh.caracal.classifier.popup.jobs; import static org.eclipse.core.runtime.Status.OK_STATUS; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.jobs.Job; import pl.edu.agh.caracal.classifier.ext.classifiers.AbstractClassifier; /** * Class for execution of training of a classifier * * @since 1.0 */ public class TrainJob extends Job { private AbstractClassifier classifier; /** * Public constructor TrainJob * * @param name Train job name * @param classifier Classifier to be trained */ public TrainJob(String name, AbstractClassifier classifier) { super(name); this.classifier = classifier; } @Override protected IStatus run(IProgressMonitor monitor) { // Long running operation - in this case classifier training // ... return OK_STATUS; } }
Standard GUI for presenting Job progress:
I have waited so long for an update to this wonderful blog… but after 4 months of waiting, I can honestly say it was worth the effort. Radek, I wanna give birth to your children:)
Pirated for the Eclipse Rich RCP application project