使用館長treeCache
時,如何確保緩存準備就緒?使用curator treeCache時,如何確保緩存準備就緒?
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
有人發現比這更好的解決方案? –