I have this code to run a job with a progress bar in java:
private void createNewJobRun(final int i) {
Job job = new Job("Experiment " //$NON-NLS-1$
+ getName()) {
@Override
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask("Experiment is running ...", 100); //$NON-NLS-1$
//call here my own functions that to the actual work
monitor.done();
return Status.OK_STATUS;
}
};
job.schedule();
}
The problem is that I want to call this function many times but only the first job runs and the others are almost simultaneously started but I never see their results...Although their progress monitor is shown. How do I wait for all of them to finish in some way or the problem is something else?
At First, you must make your own Class which is a subclass from Callable.
In this class you override the call method and do the things you do in createNewJobRun.
Now you must create a FutureTask (that is executed in a Thread to make your Job and get a result).
Example: Look at this link (at the heading FutureTask <V>
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.