Webapp: safetly update a shared List/Map in the AppContext
Posted
by al nik
on Stack Overflow
See other posts from Stack Overflow
or by al nik
Published on 2010-06-18T14:59:37Z
Indexed on
2010/06/18
15:03 UTC
Read the original article
Hit count: 309
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?
© Stack Overflow or respective owner