LeaderSelectorListener listener = new LeaderSelectorListenerAdapter()
{
public void takeLeadership(CuratorFramework client) throws Exception
{
while (true) {
try {
// ... business logic
} catch (Exception e) { // catch any exeption here
// do nothing
}
}
}
}
LeaderSelector selector = new LeaderSelector(client, path, listener);
selector.autoRequeue();
selector.start();
如代码所示,我捕获了业务代码中的任何异常,因此即使zookeeper断开连接,业务代码仍将执行,对吧?