I am trying to run multiple Jobs on my java code. They use the IProgressMonitor to update the progress bar.
Job job = new Job("My first job") {
@Override
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask("start task", 100);
//long running Hibernate save operation
monitor.done();
return Status.OK_STATUS;
}
};
job.setUser(false);
job.schedule();
I then proceed to run a second Job in a different class the same way. So the second one job will just wait until the first one is done. Is there a way to either run two at the same time, or to force the first one to pause so that the second one can run? If not, is there a way to run the progress monitor in a thread instead of a job? I tried making my classes runnable and putting the jobs in the run method, but that has the same result. Thanks.
Im not an expert in Java, but i'm pretty sure you can run tasks concurrently using java's ExecutorService found in java.util.concurrent.ExecutorService
The
java.util.concurrent.ExecutorService
interface represents an asynchronous execution mechanism which is capable of executing tasks in the background. An ExecutorService is thus very similar to a thread pool.
I'm not going to implement the executor for you, but you can read up on ExecutorService here
By default multiple Jobs do run at the same time using a pool of threads handling by the Eclipse Job manager.
You actually have to use a job scheduling rule to prevent different Jobs running at once.
Of course if one Job is doing something very processor intensive other Jobs may not get much done while it runs.
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.