当Guava Table的支持映射是线程安全的时,它是安全的吗? [英] Is a Guava Table thread safe when its backing maps are thread safe?
本文介绍了当Guava Table的支持映射是线程安全的时,它是安全的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Will Guava's Tables.newCustomTable(Map, Supplier) method return thread safe tables when supplied with thread safe maps? For example:
public static <R, C, V> Table<R, C, V> newConcurrentTable() {
return Tables.newCustomTable(
new ConcurrentHashMap<R, Map<C, V>>(),
new Supplier<Map<C, V>>() {
public Map<C, V> get() {
return new ConcurrentHashMap<C, V>();
}
});
}
该代码是否真的返回并发表?
Does that code actually return concurrent tables?
推荐答案
从文档中获取:如果多个线程同时访问该表,并且其中一个线程修改了该表,则必须在外部进行同步."
From the doc: "If multiple threads access this table concurrently and one of the threads modifies the table, it must be synchronized externally."
并发支持集还不够.
这篇关于当Guava Table的支持映射是线程安全的时,它是安全的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文