code: private BatchInfo waitForPkBatches(BatchInfoList batchInfoList, int retryInterval)
        throws InterruptedException, AsyncApiException {
      BatchInfo batchInfo = null;
      BatchInfo[] batchInfos = batchInfoList.getBatchInfo();
  
      // Wait for all batches other than the first one. The first one is not processed in PK chunking mode
      for (int i = 1; i < batchInfos.length; i++) {
        BatchInfo bi = batchInfos[i];
  
        // get refreshed job status
        bi = this.bulkConnection.getBatchInfo(this.bulkJob.getId(), bi.getId());
  
        while ((bi.getState() != BatchStateEnum.Completed)
            && (bi.getState() != BatchStateEnum.Failed)) {
          Thread.sleep(retryInterval * 1000);
          bi = this.bulkConnection.getBatchInfo(this.bulkJob.getId(), bi.getId());
          log.debug("Bulk Api Batch Info:" + bi);
          log.info("Waiting for bulk resultSetIds");
        }
  
        batchInfo = bi;
  
        // exit if there was a failure
        if (batchInfo.getState() == BatchStateEnum.Failed) {
          break;
        }
      }
  
      return batchInfo;
    }
docs: Waits for the PK batches to complete. The wait will stop after all batches are complete or on the first failed batch
  @param batchInfoList list of batch info
  @param retryInterval the polling interval
  @return the last {@link BatchInfo} processed
  @throws InterruptedException
  @throws AsyncApiException