gpt4 book ai didi

java - Google Guava Cache 引用值较弱,未给出驱逐通知

转载 作者:行者123 更新时间:2023-11-30 03:15:47 27 4
gpt4 key购买 nike

我在我们的应用程序中基于weakValues使用了google guava,如下所示。

CacheBuilder
.newBuilder()
.weakValues()
.concurrencyLevel(Runtime.getRuntime().availableProcessors())
.removalListener(removalListener)
.build(cacheLoader);

删除监听器不会在缓存弱值被删除后立即调用。我必须基于此清除 native 资源,因此我的程序结束时不会在 native 端释放内存。这是一个已知问题吗?

最佳答案

Google Guava docs ,它说如下:

Caches built with CacheBuilder do not perform cleanup and evict values "automatically," or instantly after a value expires, or anything of the sort. Instead, it performs small amounts of maintenance during write operations, or during occasional read operations if writes are rare.

还解释了他们做出此决定的原因以及可用的替代方案。

关于java - Google Guava Cache 引用值较弱,未给出驱逐通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32660230/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com