FULL PRODUCT VERSION :
ADDITIONAL OS VERSION INFORMATION :
True on all platforms
A DESCRIPTION OF THE PROBLEM :
The current pattern when submitting and event using the Observable/Observer classes is as follows:
1. setChanged
2. notifyObservers
The setChanged is required to set the variable 'changed' to true and notifyObservers will only dispatch events if 'changed' is set to true, if not it will return.
So, if 2 threads are doing that sequence:
TH1: setChnaged
TH2: setChanged
Th2: notitifyObservers # will will dispatch event for thread 2 and then reset the 'changed' to false
TH1: notitifyObservers # will return immediately because now 'changed' is set to false
=> Event for TH1 is never dispatched!
So unless we add a synchronize block around both operations this is unreliable. And adding a synchronize block around both operations implies events are being dispatched with the lock held, which is precisely what the Observable code is trying to avoid.
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
Add a synchronized block around:
setChange
notifyObservers
ADDITIONAL OS VERSION INFORMATION :
True on all platforms
A DESCRIPTION OF THE PROBLEM :
The current pattern when submitting and event using the Observable/Observer classes is as follows:
1. setChanged
2. notifyObservers
The setChanged is required to set the variable 'changed' to true and notifyObservers will only dispatch events if 'changed' is set to true, if not it will return.
So, if 2 threads are doing that sequence:
TH1: setChnaged
TH2: setChanged
Th2: notitifyObservers # will will dispatch event for thread 2 and then reset the 'changed' to false
TH1: notitifyObservers # will return immediately because now 'changed' is set to false
=> Event for TH1 is never dispatched!
So unless we add a synchronize block around both operations this is unreliable. And adding a synchronize block around both operations implies events are being dispatched with the lock held, which is precisely what the Observable code is trying to avoid.
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
Add a synchronized block around:
setChange
notifyObservers