How do you listen? I end up writing a couple of the addListenerX(), removeListenerX(), fireEventX() patterns every day almost. There are a couple of ways around to implement this with an ArrayList or maybe a HashSet or the AWTEventMulticaster. Generaly I have ended up with one of the first two for ease of implementation. A couple days a go I got the dreaded ConcurrentModificationException which when traced down was caused buy a well known problem of trying to add/remove a listener from inside the fire event method. AWTEventMulticaster is one possible solution checkout Java World Article for an example, but this ends up with a lot of code for such a every day operation. After a bit of a dig around the new Java 1.5 concurrent classes I came up on CopyOnWriteArraySet which looks to fit my problem perfectly. Fast synchronization free firing of events, thread safe add/remove and simple code use. So I end up with:
After having a little web search with the new found idea I came across PropertyChangeMulticaster by Doug Lea which is a custom CopyOnWriteArraySet implementation for bean property events. If Doug Lea says it?s the way to go then I have got to be onto the right thing? What are you using?