When should I use ConcurrentSkipListMap?

前端 未结 6 1482
孤独总比滥情好
孤独总比滥情好 2020-12-12 13:31

In Java, ConcurrentHashMap is there for better multithreading solution. Then when should I use ConcurrentSkipListMap? Is it a redundan

6条回答
  •  -上瘾入骨i
    2020-12-12 13:56

    Then when should I use ConcurrentSkipListMap?

    When you (a) need to keep keys sorted, and/or (b) need the first/last, head/tail, and submap features of a navigable map.

    The ConcurrentHashMap class implements the ConcurrentMap interface, as does ConcurrentSkipListMap. But if you also want the behaviors of SortedMap and NavigableMap, use ConcurrentSkipListMap

    ConcurrentHashMap

    • ❌ Sorted
    • ❌ Navigable
    • ✅ Concurrent

    ConcurrentSkipListMap

    • ✅ Sorted
    • ✅ Navigable
    • ✅ Concurrent

    Here is table guiding you through the major features of the various Map implementations bundled with Java 11. Click/tap to zoom.

    Keep in mind that you can obtain other Map implementations, and similar such data structures, from other sources such as Google Guava.

提交回复
热议问题