【发布时间】:2018-03-23 18:43:18
【问题描述】:
使用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
【问题讨论】:
标签: java apache-zookeeper apache-curator