0

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?

IUnknown
  • 9,301
  • 15
  • 50
  • 76

1 Answers1

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