@Override
  public void stop() throws CqClosedException, CqException {
    boolean isStopped = false;
    synchronized (cqState) {
      if (isClosed()) {
        throw new CqClosedException(
            String.format("CQ is closed, CqName : %s", cqName));
      }

      if (!(isRunning())) {
        throw new IllegalStateException(
            String.format("CQ is not in running state, stop CQ does not apply, CqName : %s",
                cqName));
      }

      Exception exception = null;
      try {
        if (proxyCache != null) {
          if (proxyCache.isClosed()) {
            throw proxyCache.getCacheClosedException("Cache is closed for this user.");
          }
          UserAttributes.userAttributes.set(proxyCache.getUserAttributes());
        }
        cqProxy.stop(this);
        isStopped = true;
      } catch (Exception e) {
        exception = e;
      } finally {
        UserAttributes.userAttributes.set(null);
      }
      if (cqProxy == null || isStopped) {
        // Change state and stats on the client side
        cqState.setState(CqStateImpl.STOPPED);
        cqService.stats().incCqsStopped();
        cqService.stats().decCqsActive();
        if (logger.isDebugEnabled()) {
          logger.debug("Successfully stopped the CQ. {}", cqName);
        }
      } else {
        // Hasn't able to send stop request to any server.
        if (exception != null) {
          throw new CqException(
              String.format("Failed to stop the cq. CqName :%s Error from last server: %s",
                  cqName, exception.getLocalizedMessage()),
              exception.getCause());
        } else {
          throw new CqException(
              String.format(
                  "Failed to stop the cq. CqName: %s. The server endpoints on which this cq was registered were not found.",
                  cqName));
        }
      }
    }
  }
Stop or pause executing the query.
geode-cq/src/main/java/org/apache/geode/cache/query/cq/internal/ClientCQImpl.java