code: public static void start() {
          synchronized (lock) {
              if (singleton != null) return;
              ZkLeaderElection leaderElection = new ZkLeaderElection();
              LeaderSelectorListener listener = new LeaderSelectorListenerAdapter() {
                  public void takeLeadership(CuratorFramework client) throws InterruptedException {
                      LOG.info("被提升为主节点！");
                      try {
                          Thread.sleep(Long.MAX_VALUE);
                      } catch (InterruptedException e) {
                          LOG.info("节点主动断开 or  主动让出主节点身份？反正此处是预期的打断！不需要打印堆栈");
                      } finally {
                          LOG.info("主节点降级为普通节点！");
                      }
                  }
              };
              leaderElection.leaderSelector = new LeaderSelector(ZkConnection.client, ZkPathManager.getMyNodeBasePath(), listener);
              leaderElection.leaderSelector.autoRequeue(); //not required, but this is behavior that you will probably expect
              leaderElection.leaderSelector.start();
              singleton = leaderElection;
              LOG.info("ZkLeaderElection启动完毕.");
          }
      }
docs: 启动主节点选举