This week's book giveaway is in the Security forum.
We're giving away four copies of Penetration Testing Basics and have Ric Messier on-line!
See this thread for details.
Win a copy of Penetration Testing Basics this week in the Security forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Listeners CopyOnWriteArrayList and removals

Richard Vieregge
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