Hi Jordan,
Please forgive my ignorance, in the below code, it's just used to avoid
unnecessary synchronizations?
I didn't see similar code before, is this a common pattern/idiom in Java?
Thanks
// first helper is synchronized when getZooKeeper is called.
Subsequent calls
// are not synchronized.
helper = new Helper()
{
private volatile ZooKeeper zooKeeperHandle = null;
private volatile String connectionString = null;
@Override
public ZooKeeper getZooKeeper() throws Exception
{
synchronized(this)
{
if ( zooKeeperHandle == null )
{
connectionString =
ensembleProvider.getConnectionString();
zooKeeperHandle =
zookeeperFactory.newZooKeeper(connectionString, sessionTimeout,
watcher, canBeReadOnly);
}
helper = new Helper()
{
@Override
public ZooKeeper getZooKeeper() throws Exception
{
return zooKeeperHandle;
}
@Override
public String getConnectionString()
{
return connectionString;
}
};
return zooKeeperHandle;
}
}
@Override
public String getConnectionString()
{
return connectionString;
}
};
--
ChuChao