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

Replace Vector usages with the java.util.ArrayList. #234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arturobernalg
Copy link
Member

No description provided.

Copy link
Contributor

@juanpablo-santos juanpablo-santos left a comment

Choose a reason for hiding this comment

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

changes requested

/* The Vector containing any preloaded WikiEventDelegates. */
private final Vector< WikiEventDelegate > m_preloadCache = new Vector<>();
/* The List containing any preloaded WikiEventDelegates. */
private final List< WikiEventDelegate > m_preloadCache = Collections.synchronizedList( new ArrayList<>() );
Copy link
Contributor

Choose a reason for hiding this comment

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

pr-wide comment:

please note that, per Collections.synchronizedList javadoc,

It is imperative that the user manually synchronize on the returned list when traversing it via Iterator, Spliterator or Stream: [...]

enhanced fors use internally an Iterator, so they also must be synchronized. Would you mind rechecking the access to the new Lists in order to ensure they remain synchronized?

Copy link
Member Author

@arturobernalg arturobernalg May 6, 2023

Choose a reason for hiding this comment

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

hi @juanpablo-santos
Another approach we can take to avoid explicitly synchronizing on the list during iteration is to use a concurrent collection instead of a synchronized collection.

Instead of using Collections.synchronizedList(), we could use java.util.concurrent.CopyOnWriteArrayList or java.util.concurrent.ConcurrentLinkedQueue, both of which are thread-safe and don't require explicit synchronization during iteration.
WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants