Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

CopyOnWriteArrayList vs Collections.synchronizedList

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?




Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by LosesMar 19, 2017 11:05 AM 4 306 Mar 19, 2017 11:05 AM
Last Post: nOrr
[Java] by FolksAug 3, 2016 06:48 AM 5 305 Aug 3, 2016 06:48 AM
Last Post: BeNT-
[.NET] by #KatOct 13, 2015 12:30 PM 2 81 Oct 13, 2015 12:30 PM
Last Post: #Kat