[英]Is there a concurrent version of this definition Java Guava collections Map
這個定義 Guava collections Map 是否有並發版本?
ListMultimap<DuplicateKey,Integer> map =
Multimaps.newListMultimap(
Maps.<DuplicateKey, Collection<Integer>>newTreeMap(),
new Supplier<List<Integer>>() {
public List<Integer> get() {
return Lists.newArrayList();
}
});
沒有並發 multimap 實現,但您可以使用Multimaps.synchronizedListMultimap
視圖包裝它,其中:
返回由指定多映射支持的同步(線程安全)多映射。
在你的情況下:
ListMultimap<DuplicateKey,Integer> synchronizedMultimap =
Multimaps.synchronizedListMultimap(map);
有關同步訪問視圖的注意事項,請閱讀完整的 javadoc :
為了保證串行訪問,對支持多映射的所有訪問都通過返回的多映射完成至關重要。
請注意,根據Github 上的 issue #135 ,Guava 本身不會有通用的並發多映射實現。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.