Jan 20, 2015 02:41 AM
(This post was last modified: Jan 20, 2015 03:14 AM by Albion.)
Hi everyone,
Making things thread safe isn't something I'm good at in Java so I thought best to ask; CopyOnWriteArrayList vs Collections.synchronizedList?
Scenario:
A console application that receives commands over a socket and can potentially perform updates on users. There is a getPermissions() method in said user class and this is where the two aforementioned lists come into play. Primarily the list will be iterated over more than it will be written to (to check users have the permission to do things of course) which is why the CopyOnWriteArrayList caught my attention. Which would be better for my intentions though? I expect reading elements/iteration to be done at least 20x more than writing to the list.
Also I don't believe I've found anywhere saying whether I need to use the synchronize keyword with the CopyOnWriteArrayList, if this is better then would I need to for reading or writing to it due to the way it works?
Making things thread safe isn't something I'm good at in Java so I thought best to ask; CopyOnWriteArrayList vs Collections.synchronizedList?
Scenario:
A console application that receives commands over a socket and can potentially perform updates on users. There is a getPermissions() method in said user class and this is where the two aforementioned lists come into play. Primarily the list will be iterated over more than it will be written to (to check users have the permission to do things of course) which is why the CopyOnWriteArrayList caught my attention. Which would be better for my intentions though? I expect reading elements/iteration to be done at least 20x more than writing to the list.
Also I don't believe I've found anywhere saying whether I need to use the synchronize keyword with the CopyOnWriteArrayList, if this is better then would I need to for reading or writing to it due to the way it works?

