private Future<RebalanceResults> submitRebalanceTask(
      final PartitionedRegionRebalanceOp rebalanceOp, final long rebalanceStartTime) {
    final InternalResourceManager manager = cache.getInternalResourceManager();
    ScheduledExecutorService ex = manager.getExecutor();

    synchronized (futureLock) {
      // this update should happen inside this.futureLock
      pendingTasks++;

      try {
        Future<RebalanceResults> future = ex.submit(() -> {
          try {
            RebalanceResultsImpl results = new RebalanceResultsImpl();
            SystemFailure.checkFailure();
            cache.getCancelCriterion().checkCancelInProgress(null);

            Set<PartitionRebalanceInfo> detailSet = null;

            detailSet = rebalanceOp.execute();

            for (PartitionRebalanceInfo details : detailSet) {
              results.addDetails(details);
            }
            return results;
          } catch (RuntimeException e) {
            logger.debug("Unexpected exception in rebalancing: {}", e.getMessage(), e);
            throw e;
          } finally {
            synchronized (futureLock) {
              pendingTasks--;
              if (pendingTasks == 0) {// all threads done
                manager.removeInProgressRebalance(RebalanceOperationImpl.this);
                manager.getStats().endRebalance(rebalanceStartTime);
              }
            }
          }
        });

        return future;
      } catch (RejectedExecutionException e) {
        cache.getCancelCriterion().checkCancelInProgress(null);
        throw e;
      }
    }
  }
Implements {@code RebalanceOperation} for rebalancing Cache resources.
geode-core/src/main/java/org/apache/geode/internal/cache/control/RebalanceOperationImpl.java