Improvement #288

Use thread-safe collections for listeners

Added by Philipp Buluschek over 3 years ago. Updated over 3 years ago.

Status:New Start date:12/04/2014
Priority:High Due date:
Assignee:Stefano Lenzi % Done:


Category:zigbee.basedriver Spent time: -
Target version:org.aaloa.zb4osgi.zigbee.basedriver-1.X
Has a patch:No Has license agreement signed:No


The current code to handle listeners is generally (here in ZigBeeDeviceImpl):

This means that for each incoming call, a full copy of the listener list is done for thread safety. In cases where writings largely outnumber readings, which is the case here as you only register listeners sometimes, eg. on startup, but iterate over them at each event, a @CopyOnWriteArrayList
or CopyOnWriteArraySet should be used instead and the whole synchronization removed.


#1 Updated by Philipp Buluschek over 3 years ago

The code got lost somehow... So here again

private void notifyClusterListner(Cluster c){
  ArrayList<ClusterListner> localCopy;
  synchronized (listeners) {
    localCopy = new ArrayList<ClusterListner>(listeners);
  if(localCopy.size() > 0)

#2 Updated by Stefano Lenzi over 3 years ago

  • Tracker changed from Task to Improvement
  • Category set to zigbee.basedriver
  • Assignee set to Stefano Lenzi
  • Priority changed from Normal to High
  • Target version set to org.aaloa.zb4osgi.zigbee.basedriver-1.X
  • Has a patch set to No
  • Has license agreement signed set to No

This is really interesting, the only drawbacks is that it requires JRE1.5, but we may have lost compatibility with JRE1.4 some years ago.

This issue affects also many other bundles: zigbee.zcl.library, zigbee.ha.driver, and others

Also available in: Atom PDF