Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractEventStream: use copy-on-write list implementation #239

Merged
merged 1 commit into from
Sep 26, 2018

Conversation

moio
Copy link
Member

@moio moio commented Sep 5, 2018

I verified in Uyuni that the previous implementation might lead to excessive monitor contention over the list, especially since iteration (in notifyListeners) requires a monitor.

In the application that I am looking at, we call notifyListeners from multiple threads, and this results in all threads but one being blocked while the notification is in progress.

This change uses a different synchronized Collection which has an extra cost on writes but never blocks reads.

for (EventListener listener : new ArrayList<>(listeners)) {
listener.notify(event);
}
for (EventListener listener : new ArrayList<>(listeners)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i remember correctly the new ArrayList here was done in case the callback of a listener modifies the listener list resulting in a ConcurentModificationException. From the CopyOnWriteArray docs it seems that it does not have this problem.

... and the iterator isguaranteed not to throw {@code ConcurrentModificationException}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, fixing.

@lucidd lucidd merged commit 0412ef8 into master Sep 26, 2018
@renner renner added this to the Version 0.15.0 milestone Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants