Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Eclipse Job framework: FIFO queue that respects priority?
Eclipse Job framework: FIFO queue that respects priority? [message #545408] Wed, 07 July 2010 16:34 Go to next message
Anders Baumann is currently offline Anders BaumannFriend
Messages: 55
Registered: July 2009
Member
Hi All.
I would like to implement a FIFO queue using the Eclipse Job framework. The
jobs should be performed one by one and no jobs should be performed at the
same time as others. To implement this I can use the
ISchedulingRule#isConflicting and compare a timestamp of the two jobs.
However, I would still like to be able to set the priority of a job
(Job#setPriority). So if I schedule a list of jobs: A,B,C,D and D has high
priority then D should be performed first when all the jobs are waiting the
be executed. As far as I can see this is not possible because the JobManager
class initializes the instance variable "waiting" as "waiting = new
JobQueue(false);". The false means "allowConflictOvertaking", so in the
queue of waiting runners it is not allowed to overtake conflicting job. But
I have to make the jobs conflicting to get the FIFO behaviour. How can I get
a FIFO queue that respects the priority property?

Thanks in advance,
Anders Baumann
Re: Eclipse Job framework: FIFO queue that respects priority? [message #545488 is a reply to message #545408] Thu, 08 July 2010 03:07 Go to previous messageGo to next message
Randy Hudson is currently offline Randy HudsonFriend
Messages: 123
Registered: July 2009
Senior Member
It sounds like you've already implemented a scheduling rule that compares timestamps. Maybe that rule should first compare the priorities, and then only compare timestamps when the priorities are equal.

It's funny, I just implemented a similar scheduling rule today. I have jobs A and B, and I want B to only be scheduled after A has been completed. However, I ran into a problem. I'm doing:

A.schedule(8000);
B.schedule();

But since A is scheduled with a delay, I have problems. Unfortunately, it seems like the scheduling rule for B is only consulted if A is currently running. But since A was delayed, B gets scheduled and runs before A.

If this is how scheduling rules work, then they aren't really useful for scheduling. Actually, aren't they just mutexes? The rules I used for jobs A and B aren't symmetric, but the javadoc for isConflicting() says that the method must be symmetric, which again sounds more like a mutex.

I'd like to be told otherwise, but it sounds like if you want to guarantee the order in which jobs run, you have to do your own scheduling and only use ISchedulingRule for avoiding deadlocks.
Re: Eclipse Job framework: FIFO queue that respects priority? [message #545526 is a reply to message #545488] Thu, 08 July 2010 07:40 Go to previous messageGo to next message
Anders Baumann is currently offline Anders BaumannFriend
Messages: 55
Registered: July 2009
Member
Hi Randy.
Thanks for your answer. I agree. It seems like the scheduling rules act more
like mutexes.
How do you suggest that I do my own scheduling if I still want to use the
Job framework? Do you suggest that I manually reorder the job queue when I
schedule a new job?

Best regards,
Anders


> It sounds like you've already implemented a scheduling rule that compares
> timestamps. Maybe that rule should first compare the priorities, and then
> only compare timestamps when the priorities are equal.

> It's funny, I just implemented a similar scheduling rule today. I have
> jobs A and B, and I want B to only be scheduled after A has been
> completed. However, I ran into a problem. I'm doing:
>
> A.schedule(8000);
> B.schedule();
>
> But since A is scheduled with a delay, I have problems. Unfortunately, it
> seems like the scheduling rule for B is only consulted if A is currently
> running. But since A was delayed, B gets scheduled and runs before A.
>
> If this is how scheduling rules work, then they aren't really useful for
> scheduling. Actually, aren't they just mutexes? The rules I used for
> jobs A and B aren't symmetric, but the javadoc for isConflicting() says
> that the method must be symmetric, which again sounds more like a mutex.
>
> I'd like to be told otherwise, but it sounds like if you want to guarantee
> the order in which jobs run, you have to do your own scheduling and only
> use ISchedulingRule for avoiding deadlocks.
Re: Eclipse Job framework: FIFO queue that respects priority? [message #545534 is a reply to message #545526] Thu, 08 July 2010 08:06 Go to previous messageGo to next message
Anders Baumann is currently offline Anders BaumannFriend
Messages: 55
Registered: July 2009
Member
One more thing: You suggest that I create a scheduling rule where I first
compare the priorities, and then only compare timestamps when the priorities
are equal. But if I do this then two jobs with different priorities are
allowed to be executed at the same time because they are not conflicting.
But I don't want this. No jobs should be executed concurrently. The job
manager should act as if the thread worker pool only has one thread so the
jobs are executed sequentially.

Best regards,
Anders
Re: Eclipse Job framework: FIFO queue that respects priority? [message #545703 is a reply to message #545534] Thu, 08 July 2010 16:56 Go to previous messageGo to next message
Randy Hudson is currently offline Randy HudsonFriend
Messages: 123
Registered: July 2009
Senior Member
	public boolean isConflicting(ISchedulingRule rule) {
		if (rule == this)
			return true;
		if (rule instanceof MyRule) {
			...
			return myrule.priority < priority
				&& myrule.timstamp < timestamp;
		}
		return false;
	}


Something like the above. I'm not sure if "<" is the correct operator.

Actually, my scenario was only for a pair of jobs, and it only worked if the first job is scheduled or running. If I scheduled a 3rd job that needed to come between the first 2, I don't think it would work reliably.

Just write your own priority queue and have a single job that services that queue. The servicing job would pull a unit of work from the queue and run it. When that unit returns, if the queue isn't empty the job can just reschedule itself (or you could just loop). When the queue receives a new work unit, it would schedule the servicing job (which is a singleton).
Re: Eclipse Job framework: FIFO queue that respects priority? [message #545801 is a reply to message #545703] Fri, 09 July 2010 07:45 Go to previous message
Anders Baumann is currently offline Anders BaumannFriend
Messages: 55
Registered: July 2009
Member
>
> public boolean isConflicting(ISchedulingRule rule) {
> if (rule == this)
> return true;
> if (rule instanceof MyRule) {
> ...
> return myrule.priority < priority
> && myrule.timstamp < timestamp;
> }
> return false;
> }
>
>
> Something like the above. I'm not sure if "<" is the correct operator.
>

But if I schedule "A B" and B has lower priority than A then they are not
conflicting which means that they can be run at the same time.This is not
allowed in my system.

> Actually, my scenario was only for a pair of jobs, and it only worked if
> the first job is scheduled or running. If I scheduled a 3rd job that
> needed to come between the first 2, I don't think it would work reliably.
>
> Just write your own priority queue and have a single job that services
> that queue. The servicing job would pull a unit of work from the queue
> and run it. When that unit returns, if the queue isn't empty the job can
> just reschedule itself (or you could just loop). When the queue receives
> a new work unit, it would schedule the servicing job (which is a
> singleton).

What would be the advantage of using the Eclipse Job like you describe
compared to using for instance the Executors class, like
Executors#newSingleThreadScheduledExecutor? Don't I loose the advantages of
the Eclipse Job framework when I am not using it's own queue?

Thanks in advance,
Anders
Previous Topic:Read-only editor content: ByteArrayStorage & ByteArrayStorageEditorInput
Next Topic:"org.junit4" in target platform?
Goto Forum:
  


Current Time: Thu Mar 28 10:21:11 GMT 2024

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

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

Back to the top