下面是zookeeper中的一个应用
private AddressTuple getAddrs() {
AddressTuple addrs = myAddrs.get();
if (addrs != null) {
return addrs;
}
try {
synchronized (QV_LOCK) {
addrs = myAddrs.get();
while (addrs == null) {
QV_LOCK.wait();
addrs = myAddrs.get();
}
return addrs;
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}