Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Listeners CopyOnWriteArrayList and removals

 
Richard Vieregge
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A common suggestion to avoid ConcurrentModificationExceptions when iterating through listeners is to use a CopyOnWriteArrayList.

But isn't there a possible issue that you will then call a listener that just de-registered? If the listening object wasn't expecting this, it could cause problems.

What is the usual solution to this? Require any listener objects that de-register to keep a volatile state variable indicating their registration status, and to ignore the event if they aren't registered?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic