0

I have the need to store key value pairs which should preserve the order. Reverse or forward does not matter.

The environment is multi threaded so this structure need to be thread safe as well. During specific events I need to read the entire map push to db and clear all.

This structure is supposed to be shared so it is possible that other threads attempt to write into it at the same time.

I initially used a LinkedHashMap but it is not thread safe and so I am hitting concurrentModificationException

Vik
  • 8,721
  • 27
  • 83
  • 168
  • One alternative would be to represent your key-value pairs as tuples (pairs). If reads will be more common than writes, then you can use `CopyOnWriteArrayList` to provide high concurrency, thread safety, and safe iteration. – scottb Feb 10 '16 at 03:57
  • Please see [this similar question](http://stackoverflow.com/questions/1391918/does-java-have-a-linkedconcurrenthashmap-data-structure). – Hovercraft Full Of Eels Feb 10 '16 at 03:57
  • no actually most of the time there would be only writes. there are only a very few event points when i need to read all the entries and clean the map. – Vik Feb 10 '16 at 04:12

0 Answers0