Implementing a concurrent LinkedHashMap

后端 未结 5 823
面向向阳花
面向向阳花 2021-01-04 06:15

I\'m trying to create a concurrent LinkedHashMap for a multithreaded architecture.

If I use Collections#synchronizedMap(), I would have to use synchroni

5条回答
  •  不知归路
    2021-01-04 06:23

    Use Collections#synchronizedMap().

    As per my belief, if I use Collections.synchronizedMap(), I would have to use synchronized blocks for getter/setter.

    This is not true. You only need to synchronize the iteration on any of the views (keyset, values, entryset). Also see the abovelinked API documentation.

提交回复
热议问题