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 断开连接,业务代码仍然会执行,对吧?