[英]Is there a concurrent version of this definition Java Guava collections Map
Is there a concurrent version of this definition 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();
}
});
There's no concurrent multimap implementation, but you can wrap it with Multimaps.synchronizedListMultimap
view, which:没有并发 multimap 实现,但您可以使用Multimaps.synchronizedListMultimap
视图包装它,其中:
Returns a synchronized (thread-safe) multimap backed by the specified multimap.返回由指定多映射支持的同步(线程安全)多映射。
In your case:在你的情况下:
ListMultimap<DuplicateKey,Integer> synchronizedMultimap =
Multimaps.synchronizedListMultimap(map);
Read complete javadoc for caveats regarding synchronized access to views:有关同步访问视图的注意事项,请阅读完整的 javadoc :
In order to guarantee serial access, it is critical that all access to the backing multimap is accomplished through the returned multimap.为了保证串行访问,对支持多映射的所有访问都通过返回的多映射完成至关重要。
Note that there'll be no general-purpose concurrent multimap implementation in Guava itself, according to issue #135 on Github .请注意,根据Github 上的 issue #135 ,Guava 本身不会有通用的并发多映射实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.