How to implement ConcurrentHashMap with features similar in LinkedHashMap?

后端 未结 6 812
离开以前
离开以前 2021-02-04 05:14

I have used LinkedHashMap with accessOrder true along with allowing a maximum of 500 entries at any time as the LRU cache for data. But due to scalabil

6条回答
  •  青春惊慌失措
    2021-02-04 05:43

    Wrap the map in a Collections.synchronizedMap(). If you need to call additional methods, then synchronize on the map that you got back from this call, and invoke the original method on the original map (see the javadocs for an example). The same applies when you iterate over the keys, etc.

提交回复
热议问题