code: @Override
      public void run() {
  
          if (this.state != null && this.state.cancel) {
              // we were already cancelled, don't run, but still post completion
              this.state.documentCounter = 0;
              this.state.batchCounter = 0;
              runComplete(null);
              return;
          }
          // reset internal state
          this.state = new State();
  
          Throwable errorInfo = null;
  
          try {
  
              replicate();
  
          } catch (Throwable e) {
              logger.log(Level.SEVERE,String.format("Batch %s ended with error:", this.state.batchCounter),e);
              errorInfo = e;
          }
  
          runComplete(errorInfo);
      }
docs: Handle exceptions in separate run() method to allow replicate() to
  just return when cancel is set to true rather than having to keep
  track of whether we terminated via an error in replicate().