是否存在所有值都是弱引用的 Map 类?类似于 WeakHashMap,但用于值而不是键。
提前致谢...
最佳答案
您可以使用 MapMaker这是 Guava 的一部分。
"Java DOC:A ConcurrentMap builder, providing any combination of these features: soft or weak keys, soft or weak values, timed expiration, and on-demand computation of values."
ConcurrentMap<Key, Graph> graphs = new MapMaker()
.concurrencyLevel(32)
.softKeys()
.weakValues()
.expiration(30, TimeUnit.MINUTES)
.makeComputingMap(
new Function<Key, Graph>() {
public Graph apply(Key key) {
return createExpensiveGraph(key);
}
});
它几乎是可配置的。
关于java - 具有弱引用值而不是键的 WeakHashMap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21153113/