Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Concurrent Jobs?
Concurrent Jobs? [message #435065] Tue, 09 August 2005 18:08 Go to next message
Aashish Patil is currently offline Aashish PatilFriend
Messages: 39
Registered: July 2009
Member
Hi,

I have a job that downloads files. I want two or more instances of this
job to be able to run concurrently. However, when I start two or more
instances, they seem to be getting executed serially instead of
concurrently i.e the second instance waits for the first to complete, the
third waits for the second to complete and so on. I have not used join()
anywhere.

DownloadJob dj = new DownloadJob();
//set custom properties

//need to do this to show progress
dj.setUser(true);

dj.schedule();

Are there any special settings needed to enable concurrency.

Any thoughts on how I can limit the number of job instances. For example,
I don't want more than 5 instances of the DownloadJob running
concurrently. The sixth or greater job would have to wait for one of 5 to
complete. Thus, how can set the number of threads in the pool.


Thank you
Regards,
Aashish
Re: Concurrent Jobs? [message #435235 is a reply to message #435065] Wed, 10 August 2005 18:57 Go to previous messageGo to next message
John Arthorne is currently offline John ArthorneFriend
Messages: 176
Registered: July 2009
Senior Member
By default, jobs will run concurrently. You would need to add an
ISchedulingRule to the job (Job.setRule) to cause them to run
sequentially. There is no support for limiting the number of instances
of a particular job that can run concurrently - you would have to manage
this yourself.
--

Aashish Patil wrote:
> Hi,
>
> I have a job that downloads files. I want two or more instances of this
> job to be able to run concurrently. However, when I start two or more
> instances, they seem to be getting executed serially instead of
> concurrently i.e the second instance waits for the first to complete,
> the third waits for the second to complete and so on. I have not used
> join() anywhere.
> DownloadJob dj = new DownloadJob();
> //set custom properties
>
> //need to do this to show progress dj.setUser(true);
>
> dj.schedule();
>
> Are there any special settings needed to enable concurrency.
>
> Any thoughts on how I can limit the number of job instances. For
> example, I don't want more than 5 instances of the DownloadJob running
> concurrently. The sixth or greater job would have to wait for one of 5
> to complete. Thus, how can set the number of threads in the pool.
>
>
> Thank you
> Regards,
> Aashish
>
Re: Concurrent Jobs? [message #435253 is a reply to message #435235] Thu, 11 August 2005 01:14 Go to previous messageGo to next message
Aashish Patil is currently offline Aashish PatilFriend
Messages: 39
Registered: July 2009
Member
Hi John,

The problem is that they are not running concurrently. Instead the
execution is sequential. I want it to be concurrent.

Thanks
Aashish
Re: Concurrent Jobs? [message #435297 is a reply to message #435253] Thu, 11 August 2005 14:57 Go to previous messageGo to next message
John Arthorne is currently offline John ArthorneFriend
Messages: 176
Registered: July 2009
Senior Member
Aashish Patil wrote:
> The problem is that they are not running concurrently. Instead the
> execution is sequential. I want it to be concurrent.

Jobs run concurrently. If yours are not, then one must be blocking the
other one by acquiring some kind of lock. Here is an example:

public class JobTest {
static class TestJob extends Job {
public TestJob(String name) {
super(name);
}
protected IStatus run(IProgressMonitor monitor) {
for (int i = 0; i < 5; i++) {
System.out.println(getName() + ' ' + i);
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
}
return Status.OK_STATUS;
}
};
public static void main(String[] args) {
TestJob a = new TestJob("A");
TestJob b = new TestJob("B");
a.schedule();
b.schedule();
}
}

The output when I run this is:

A 0
B 0
A 1
B 1
A 2
B 2
A 3
B 3
A 4
B 4

This shows that the jobs are running concurrently.
--
Re: Concurrent Jobs? [message #435426 is a reply to message #435297] Wed, 17 August 2005 23:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kent.generatescape.com

did you solve this?

I am experiencing similiar behavior with jobs, and I can't find any
behaviour that would be cause blocking.

"John Arthorne" <john@eclipsefaq.org> wrote in message
news:ddfp0f$lsb$1@news.eclipse.org...
> Aashish Patil wrote:
>> The problem is that they are not running concurrently. Instead the
>> execution is sequential. I want it to be concurrent.
>
> Jobs run concurrently. If yours are not, then one must be blocking the
> other one by acquiring some kind of lock. Here is an example:
>
> public class JobTest {
> static class TestJob extends Job {
> public TestJob(String name) {
> super(name);
> }
> protected IStatus run(IProgressMonitor monitor) {
> for (int i = 0; i < 5; i++) {
> System.out.println(getName() + ' ' + i);
> try {
> Thread.sleep(100);
> } catch (InterruptedException e) {}
> }
> return Status.OK_STATUS;
> }
> };
> public static void main(String[] args) {
> TestJob a = new TestJob("A");
> TestJob b = new TestJob("B");
> a.schedule();
> b.schedule();
> }
> }
>
> The output when I run this is:
>
> A 0
> B 0
> A 1
> B 1
> A 2
> B 2
> A 3
> B 3
> A 4
> B 4
>
> This shows that the jobs are running concurrently.
> --
Re: Concurrent Jobs? [message #435600 is a reply to message #435065] Fri, 19 August 2005 08:03 Go to previous message
Alex Blewitt is currently offline Alex BlewittFriend
Messages: 946
Registered: July 2009
Senior Member
The most likely cause of serialised behaviour in this manner is if you're using a common 'synchronised' method to kick stuff off. For example:

public class DownloadManager {
public synchronised void download(String url) {
// ...
}
}

Even if you have multiple Jobs running this, they'll all be serialised anyway, since they're locking on the same synchronised instance. You might want to do a search for your code and find out if there's something in your code that looks fishy.

The other approach would be to run a test by creating 5 new Thread objects, and in each doing the call to your download implementation. At least that will tell you if it's a problem with your configuration/implementation of Job, or a glitch in your download code.
Previous Topic:use PropertySheet with own Editor
Next Topic:Multiplatform Web Start export for RCP app
Goto Forum:
  


Current Time: Sun Dec 08 03:19:55 GMT 2024

Powered by FUDForum. Page generated in 0.05122 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top