java - Webapp: safetly update a shared List/Map in the AppContext -


There are lists and maps in my WebAppContext. Most of the time, they are read only by many threads, but sometimes Some data updates need to be added or added.
I am thinking that what is the best way to do this without doing the concurrent counseling concept.

I think I can use what I can do - I do not need to synchronize in every reading job - I can update the security list while others read it Are there.

Is this the best solution? What about the map?

The typical archive you want to be careful while using CopyOnWriteArrayList reads 80% (on a very wide scale) And writes 19% and 1% is removed. CopyOnWriteArraylist performs poorly under those conditions. One of the best uses of CopyOnWriteArrayList is when reading ~ 90-95% too much will be very poor performance (class because an inability to throw exception exception, because a collections.sort is terrible).

Actually, if you read and write something, CopyOnWriteArrayList is fantastic, though, if you are not, you can consider the collection. If you want to ensure that the block is blocked, then the CopyOnWriteArrayList will fit clearly.

ConcurrentHashMap is great for you as a replacement for any map implementation (at least) it will not be blocked on reading, and only blocks specific buckets when writing, so it is very fast.


Comments