Eclipse’s EventManager

Yesterday I reached a ConcurrentModificationException while notifying the selection listeners registered on my ViewPart. One listener was trying to remove itself of the listeners list while it was notified.

After a quick look into several Eclipse’s ViewPart classes providing selection change events it seems they all use the org.eclipse.core.commands.common.EventManager abstract class.

Here is this class description:

“A manager to which listeners can be attached. This handles the management of a list of listeners — optimizing memory and performance. All the methods on this class are guaranteed to be thread-safe”

This class also guarantees using org.eclipse.core.runtime.ListenerList class that a listener can be removed while we are itterating on the getListeners() method’s result.

This existing class was exactly the answer to my need.

Conclusion here is : REUSE and step into an Eclipse’s plugin already solving your problem (it’s generally easy to find such a plugin) to find the “right” answer.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s