Enough-Software/glaze — Issue #5: Possibly unnecessary synchronization on UiApplication.getEventLock()
Author: hannsl
Created: 2011-12-10 23:47:43+00:00
State: open

I have seen several instances in the code where synchronization is performed on UiApplication.getEventLock(). The most frequently occurring instances of this are in the islayouting and applyfieldstyles methods. Having performed some quick tests, it appears that these methods are always invoked on the same thread and therefore dont require synchronization.

Furthermore, the StyleSheet class contains several examples of the following:

protected void notifyLoaded(String url) {
synchronized (UiApplication.getEventLock()) {
for (int index = 0; index < this.listeners.size(); index++) {
StyleSheetListener listener = (StyleSheetListener) this.listeners
.elementAt(index);
listener.onLoaded(url);
}
}
}

I believe the correct way to achieve synchronization in this case would be:

protected void notifyLoaded(final String url) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
for (int index = 0; index < listeners.size(); index++) {
StyleSheetListener listener = (StyleSheetListener) listeners.elementAt(index);
listener.onLoaded(url);
}
}
});
}