Eclipse bookmarking API: how to track progress for a task scheduled by another job?
What is the correct way to use progress monitors for an Eclipse Job that schedules and attaches to another Eclipse Job? I would like the sub-task to be related to the main task.
Ideally, I would like to say that the sub-task is working with SubProgressMonitor
that created from the main monitor, but I don't see a way to do this. I have looked at the method Job.setProgressGroup(..., ...)
, but the documentation indicates that the group should be created with IJobManager.createProgressGroup()
.
Here's a snippet for context:
@Override
protected IStatus run(final IProgressMonitor monitor) {
try {
monitor.beginTask("My Job A", 100);
MyJobB subtask = new MyJobB();
// how how should subtask progress be tracked?
subtask.schedule();
subtask.join();
return Status.OK_STATUS;
} catch (Exception ex) {
// return error status
} finally {
monitor.done();
}
}
source to share
To answer the original question - you can do it like this:
public class MyJobA extends Job {
private IProgressMonitor pGroup = Job.getJobManager().createProgressGroup();
public MyJobA() {
super("My Job A");
setProgressGroup(pGroup, 50);
}
@Override
protected IStatus run(IProgressMonitor monitor) {
MyJobB subtask = new MyJobB();
subtask.setProgressGroup(pGroup, 50);
pGroup.beginTask("My Jobs", 100);
try {
monitor.beginTask("My Job A", 10);
try {
// do work
monitor.worked(...);
} finally {
monitor.done();
}
subtask.schedule();
subtask.join();
} finally {
pGroup.done();
}
return Status.OK_STATUS;
}
}
It's a little more elegant if you create a progress group from the outside:
IProgressMonitor group = Job.getJobManager().createProgressGroup();
try {
group.beginTask("My Tasks", 200);
MyJobB b = new MyJobB();
b.setProgressGroup(group, 100);
b.schedule();
MyJobC c = new MyJobC();
c.setProgressGroup(group, 100);
c.schedule();
b.join();
c.join();
} finally {
group.done();
}
Note that a job that has not yet been scheduled will appear as "completed":
If possible, I would consider merging two Jobs and using SubMonitor .
source to share