Implementing a concurrent LinkedHashMap

后端 未结 5 781
面向向阳花
面向向阳花 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:25

    If you use synchronizedMap, you don't have to synchronize externally, except for iteration. If you need to preserve the ordering of the map, you should use a SortedMap. You could use ConcurrentSkipListMap, which is thread-safe, or another SortedMap in combination with synchronizedSortedMap.

提交回复
热议问题