Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 366170

Summary: JobManager does not wake up a scheduled job
Product: [Eclipse Project] Platform Reporter: Ivan Motsch <ivan.motsch>
Component: RuntimeAssignee: John Arthorne <john.arthorne>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: john.arthorne, pwebster, remy.suen, sptaszkiewicz, stephan.leichtvogt, yevshif
Version: 3.7.1   
Target Milestone: 3.8 M5   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 368581    
Attachments:
Description Flags
Hello World example of the issue none

Description Ivan Motsch CLA 2011-12-09 05:49:45 EST
Created attachment 208159 [details]
Hello World example of the issue

We have an issue that blocks processing of an application.

It turns out that the job manager does not activate (run) a scheduled job after the specified time, even more it never starts it at all.

We traced it down to the job scheduling framework in JobManager.
That made it possible to create a hello world example.
Just open it in a workspace and launch the products/hello.product

The hello world is attached and does the following:
Main: schedule job A
Main: schedule job C
A: schedule job B and join on it
B: do sleep until a stop flag is set to true.
C: set the stop flag

Even more, all jobs scheduled after A (has started running) are never run and awakened. Therefore i added some info jobs that just say hello.

In order to not wait forever, i added a sleep 2000 after which it breaks up waiting in the main thread.
When calling IJobManager.resume at that point, it magically awakenes all ready-to-run jobs and runs them. But the javadoc says that calling resume() does nothing when the job manager is active.

Expected behaviour:
I expect that whenever scheduling a Job say schedule(200) it is run after 200 ms +/- some acceptable delay. Never running it is breaking the concept of having parallel jobs in a system.
Comment 1 Ivan Motsch CLA 2011-12-09 07:43:11 EST
Addendum: When i run it in debug mode, it only happens in 60% of the launches.
When i run it in run model it happens in 95% of the launches.
When i add a loop in the start method to call the process n times, it only happen in 1% of the cases.
So i guess there might be some timing issue that is greater, the less system delays are used (debug, jm profiling etc.)
Comment 2 Ivan Motsch CLA 2011-12-12 03:08:44 EST
Addendum: tested it also on Platforms win xp and macosx, as well as eclipse 3.6.2 and had the same effect.
Comment 3 Ivan Motsch CLA 2011-12-12 04:09:12 EST
In case you need help in the analysis of the cause of this effect, just give me a note.
Comment 4 John Arthorne CLA 2012-01-13 14:09:29 EST
Wow, I can reproduce this easily. It is a case of starvation because there are no idle worker threads and both of the existing worker threads are blocked. The conditions to reproduce seem to be:

- Start with only one existing worker thread
- Jobs A and C are scheduled with a delay. There is an idle worker thread so nothing is spawned
- Job A causes Job B to be scheduled. This spawns a new worker thread.
- Job B starts. Usually immediately before starting a job, a worker checks to make sure there is at least one more worker available if there are waiting jobs. However since C is still sleeping it doesn't spawn a new worker

-> Now A and B are running, and there are no idle workers to process C when its time comes.
Comment 5 John Arthorne CLA 2012-01-13 14:16:21 EST
Fix, and regression test based on Ivan's example.

http://git.eclipse.org/c/platform/eclipse.platform.runtime.git/commit/?id=7c6740abca3b0243a4a745665df56d4372a1e16d