code: static String acquireLock(ZooKeeper zookeeper, String lockNode) throws KeeperException, InterruptedException {
          // Inspired by the queueing algorithm suggested here:
          // http://zookeeper.apache.org/doc/trunk/recipes.html#sc_recipes_Queues
  
          // Acquire a place in the queue by creating an ephemeral, sequential znode.
          String placeInLine = takeQueueTicket(zookeeper, lockNode);
          logger.debug("Acquiring lock, waiting in queue: {}.", placeInLine);
  
          // Wait in the queue until our turn has come.
          return waitInLine(zookeeper, lockNode, placeInLine);
      }
docs: Try to acquire a lock on for choosing a resource. This method will wait until it has acquired the lock.
  
  @param zookeeper ZooKeeper connection to use.
  @param lockNode Path to the znode representing the locking queue.
  @return Name of the first node in the queue.