I want to register a new eventHandler in an event, I get a java.util.ConcurrentModificationException upon doing this. Is there a reason that this is implemented in this way?
I had to write my own ApplicationEventMulticaster to get this working...
Code:package net.mlw.newsfutures.gui; import java.util.HashSet; import java.util.Set; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ApplicationEventMulticaster; public class SimpleApplicationEventMulticaster implements ApplicationEventMulticaster { /** Set of listeners */ //private final Set applicationListeners = new HashSet(); private final List applicationListeners = new ArrayList(); public synchronized void addApplicationListener(ApplicationListener listener) { this.applicationListeners.add(listener); } public synchronized void removeApplicationListener(ApplicationListener listener) { this.applicationListeners.remove(listener); } public synchronized void removeAllListeners() { this.applicationListeners.clear(); } public synchronized ApplicationListener[] getApplicationListeners() { return (ApplicationListener[]) applicationListeners.toArray(new ApplicationListener[applicationListeners.size()]); } public void multicastEvent(ApplicationEvent event) { ApplicationListener[] listeners = getApplicationListeners(); for (int i = 0, length = listeners.length; i < length; i++) { listeners[i].onApplicationEvent(event); } } }


Reply With Quote