使用 curatortreeCache
时,如何确保缓存已准备就绪?
之后cache.start()
,如果我getCurrentData
立即调用,它将返回null
,那么如何确保缓存已准备好?有人可以举个例子吗?谢谢
client = CuratorFrameworkFactory.builder()
.connectString(connectionString)
.retryPolicy(new ExponentialBackoffRetry(zkConnectionTimeoutMs, 3))
.sessionTimeoutMs(zkSessionTimeoutMs)
.build();
client.start();
cache = new TreeCache(client, rootPath);
cache.start();
ChildData child = cache.getCurrentData(rootPath); // child is null
Thread.sleep(50); // must sleep for a while
child = cache.getCurrentData(rootPath); // child is ok