Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 334632 - IJobManager.beginRule(..) can use 100% of my CPU for seconds
Summary: IJobManager.beginRule(..) can use 100% of my CPU for seconds
Status: CLOSED DUPLICATE of bug 320329
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Runtime (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: John Arthorne CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-18 08:09 EST by Markus Schorn CLA
Modified: 2011-01-23 04:52 EST (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Schorn CLA 2011-01-18 08:09:18 EST
Version: 3.7.0  Build id: I20101208-1300

I noticed that once and a while my IDE uses up 100% of my CPU. I have tracked down the issue to the situation reproducable with the sample code below. Basically I have a job that is waiting for another one to complete and the waiting job blocks the IJobManager.beginRule(). In this case the call to 
IJobManager.beginRule() runs in a loop consuming lots of CPU cycles.


// Sample code
class Test {
    // A simple scheduling rule
    class PerInstance implements ISchedulingRule {
        public boolean contains(ISchedulingRule rule) {
	    return rule == this;
	}
        public boolean isConflicting(ISchedulingRule rule) {
            return rule == this;
        }
    }
	
    public void run() {
        Job j1= new Job("job1") {
            protected IStatus run(IProgressMonitor monitor) {
                 try {
                     Thread.sleep(15000);  // Blocks the second job for 15 secs
                 } catch (InterruptedException e) {}
                 return Status.OK_STATUS;
            }
        };
        Job j2= new Job("job2") {
            protected IStatus run(IProgressMonitor monitor) {
                return Status.OK_STATUS;
        }
    };
		
    ISchedulingRule rule1= new PerInstance();
    ISchedulingRule rule2= new PerInstance();
		
    j1.setRule(rule1);                                 
    j2.setRule(MultiRule.combine(rule1, rule2));   
		
    j1.schedule();  // Job runs for 15sec.
    j2.schedule();  // Job is blocked by j1 for 15 sec.

    // This call runs in a loop until j2 finishes and consumes the CPU       
    Job.getJobManager().beginRule(rule2, new NullProgressMonitor());
    
    // Clean up
    Job.getJobManager().endRule(rule2);
}
Comment 1 John Arthorne CLA 2011-01-21 13:28:00 EST

*** This bug has been marked as a duplicate of bug 320329 ***