Vert.x 中的 sharedData AsyncMap 存在多长时间?

How long-lived is a sharedData AsyncMap in Vert.x?

如果我像这样获取 AsyncMap

if (vertx.isClustered()) {
    vertx.sharedData().<String, MyEntity>getClusterWideMap("entities", 
            res -> {
                AsyncMap<String, MyEntity> myMap = res.result();
                // Do something with the myMap
            });
}

地图"long-lived"怎么样?它是否保持自身同步?

我可以在构造函数中获取它,存储在一个字段中,然后一遍又一遍地使用它吗?

或者我是否需要在每次需要时调用 getClusterWideMap 并且只在 lambda 中使用它?

您可以保留对 AsyncMap 的引用。再次调用 getClusterWideMap 将为您提供对同一底层数据结构的另一个引用,由集群管理器提供。