Bug 551106 - Job change events are not ordered
Summary: Job change events are not ordered
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Runtime (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: platform-runtime-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-09-16 07:46 EDT by Vasili Gulevich CLA
Modified: 2019-09-16 08:01 EDT (History)
0 users

See Also:


Attachments
Failing Junit test (3.93 KB, text/plain)
2019-09-16 08:01 EDT, Vasili Gulevich CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vasili Gulevich CLA 2019-09-16 07:46:49 EDT
If a single org.eclipse.core.runtime.jobs.Job is scheduled multiple times, there are no guarantees on order of notifications received by IJobChangeListener.

For example, events may be observed in a following order:
- scheduled
- scheduled
- done
- done

This may confuse API user, as there is a strong guarantee on exclusive execution of a single Job instance.

Javadoc on org.eclipse.core.runtime.jobs.IJobChangeListener says:


> Listeners are notified of all job state changes, but whether the state change occurs before, during, or after listeners are notified is unspecified.


It is not clear from this description, that order of invocations for listeners themselves is also not guaranteed.

Please update Javadoc to reflect relaxed guarantees on listener execution order.

The importance of notification order can be illustrated by a naive example:

Job job = ...;

job.addJobChangeListener(new JobChangeAdapter() {
  private final AtomicReference<Object> resource = new AtomicReference<>();
  void scheduled(...) {
    resource.set(new Datum());
  }
  void done(...) {
    resource.get().update(); // Null pointer exception
    resource.set(null);
  }
});

job.schedule();
job.schedule();
job.schedule();
Comment 1 Vasili Gulevich CLA 2019-09-16 08:01:12 EDT
Created attachment 279884 [details]
Failing Junit test

Attached is a failing Junit test that expects a certain order of notifications to be observed. It fails on iteration 3000 - 40000.

This high "stability" means that most implementers of listener will never realize there is a bug in their program, leading to random errors on CI and end-user workstations.