Webapp: safetly update a shared List/Map in the AppContext
- by al nik
I've Lists and Maps in my WebAppContext.
Most of the time these are only read by multiple Threads but sometimes there's the need to update or add some data.
I'm wondering what's the best way to do this without incurring in a ConcurrentModificationException.
I think that using CopyOnWriteArrayList I can achieve what I want in terms of - I do not have to sync on every read operation- I can safety update the list while other threads are reading it.
Is this the best solution? What about Maps?