如果我像这样获取 AsyncMap
:
if (vertx.isClustered()) {
vertx.sharedData().<String, MyEntity>getClusterWideMap("entities",
res -> {
AsyncMap<String, MyEntity> myMap = res.result();
// Do something with the myMap
});
}
map 的“生命周期”有多长?它保持同步吗?
我可以在构造函数中获取它,将其存储在字段中,然后反复使用它吗?
或者我是否需要在每次需要时调用 getClusterWideMap 并且仅在 lambda 中使用它?
最佳答案
您可以保留对AsyncMap
的引用。再次调用 getClusterWideMap
将为您提供对集群管理器提供的同一底层数据结构的另一个引用。
关于java - Vert.x 中的共享数据 AsyncMap 的生命周期有多长?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59168245/