[英]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.