How to run more than one job concurrently in RCP?
I want to know how to execute more than one job in Eclipse at a time. I want to run mo开发者_运维知识库re than one job concurrently in RCP.
A Job
more or less wraps a Thread
and all started (scheduled) job instances run in parallel.
Suggestion for further reading:
- On the Job: the Eclipse Jobs API
Use Threading to run more than one job at a time.
Thread th = new Thread() {
public void run() {
//Here is a thread that you can use wherever you want in your code
}
};
th.start();
See Eclipse RCP: Only one Job runs at a time?
Jobs can optionally finish their execution asynchronously (in another thread) by returning a result status of
ASYNC_FINISH
. Jobs that finish asynchronously must specify the execution thread by callingsetThread
, and must indicate when they are finished by calling the method done.
A few years later, you now have the opposite issue, which is to limit the number of concurrent jobs.
That is why Eclipse 4.5M4 will include now (Q4 2014) a way to Support for Job Groups with throttling.
See bug 432049:
Eclipse provides a simple Jobs API to perform different tasks in parallel and in asynchronous fashion. One limitation of the Eclipse Jobs is that there is no easy way to limit the number of worker threads being used to execute jobs.
This may lead to a thread pool explosion when many jobs are scheduled in quick succession. Due to that it’s easy to use Jobs to perform different unrelated tasks in parallel, but hard to implement thousands of Jobs co-operating to complete a single large task.Eclipse currently supports the concept of Job Families, which provides one way of grouping with support for join, cancel, sleep, and wakeup operations on the whole family.
To address all these issue we would like to propose a simple way to group a set of Eclipse Jobs that are responsible for pieces of the same large task.
The API would support throttling, join, cancel, combined progress and error reporting for all of the jobs in the group and the job grouping functionality can be used to rewrite performance critical algorithms to use parallel execution of cooperating jobs.
You can see the implementation in this commit 26471fa
精彩评论