I have a list of accounts that will be updated - not too frequent ~1-2 times a day.
There would be a 'contains' lookup on this data at much regular interval.
An ideal data structure would have been ConcurrentLinkedList ,which unfortunately isnt around.
Is CopyOnWriteArrayList the sole preferred option?
Asked
Active
Viewed 195 times
0

IUnknown
- 9,301
- 15
- 50
- 76
-
Hi Why You are not thinking some kind of Tree or hash map data structure where look up will first – gati sahu May 17 '17 at 07:04
-
`CopyOnWriteArrayList` sounds perfect for your use case. What do you have against it? – shmosel May 17 '17 at 07:04
-
You may be looking for Set
set = Collections.newSetFromMap(new ConcurrentHashMap – gati sahu May 17 '17 at 07:15());
1 Answers
0
If you are reading mostly , why you need concurrent data structure. Instead you can use HashSet or HashMap. It will make read faster. It is updated so less frequently then u can synchronise the writing part explicitly.

Sagar Gandhi
- 925
- 6
- 20
-
This seems to be wrong ,because while one thread writing other thread should not read stale data. – gati sahu May 17 '17 at 07:09
-
But it is updated so infrequent , you can take care of that explicitly using locks. right ?. Also Your reading performance should be faster in your case, List has o(n) complexity for contains. – Sagar Gandhi May 17 '17 at 07:11
-
then you have to implement read /write lock separately not explicit lock ,where multiple thread can read.May be set can be use Set
set = Collections.newSetFromMap(new ConcurrentHashMap – gati sahu May 17 '17 at 07:16());