Thread-safe HashSet with Guava Collections

后端 未结 4 2248
攒了一身酷
攒了一身酷 2021-02-19 04:13

Like the title says, i would like to get a thread-safe HashSet using Guava Collections.
Are any available?

4条回答
  •  礼貌的吻别
    2021-02-19 05:09

    Java 8 introduces new way to create concurrent hash set - ConcurrentHashMap.newKeySet()

    Set set = ConcurrentHashMap.newKeySet();
    

    It's shorter than wrapping in Collections.newSetFromMap

提交回复
热议问题