code: private void checkEnd() {
      if (ended && !closed && children == 0) {
        closed = true;
        connection.doBatchEnd(id, endArgs);
        if (endHandler != null) {
          endHandler.handle((Void) null);
        }
      }
    }
docs: Checks whether the batch is complete.