@Override
  protected void doShutdown() {

    if (!this.isRunning()) {
      return;
    }

    try {
      synchronized (consumersMonitor) {
        if (this.consumers != null) {
          for (BlockingQueueConsumer consumer : this.consumers.keySet()) {
            consumer.setQuiesce(this.shutdownTimeout);
          }
        }
      }
      logger.info("Waiting for workers to finish.");
      boolean finished = cancellationLock.await(shutdownTimeout, TimeUnit.MILLISECONDS);
      if (finished) {
        logger.info("Successfully waited for workers to finish.");
      } else {
        logger.info("Workers not finished.  Forcing connections to close.");
      }
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      logger.warn("Interrupted waiting for workers.  Continuing with shutdown.");
    }

    synchronized (this.consumersMonitor) {
      this.consumers = null;
    }
  }
  /**
   * Specify the number of concurrent consumers to create. Default is 1.
   *
   * <p>Raising the number of concurrent consumers is recommended in order to scale the consumption
   * of messages coming in from a queue. However, note that any ordering guarantees are lost once
   * multiple consumers are registered. In general, stick with 1 consumer for low-volume queues.
   * Cannot be less than {@link #maxConcurrentConsumers} (if set).
   *
   * @see #setMaxConcurrentConsumers(int)
   * @param concurrentConsumers the minimum number of consumers to create.
   */
  public void setConcurrentConsumers(final int concurrentConsumers) {
    Assert.isTrue(concurrentConsumers > 0, "'concurrentConsumers' value must be at least 1 (one)");
    if (this.maxConcurrentConsumers != null) {
      Assert.isTrue(
          concurrentConsumers <= this.maxConcurrentConsumers,
          "'concurrentConsumers' cannot be more than 'maxConcurrentConsumers'");
    }
    synchronized (consumersMonitor) {
      if (logger.isDebugEnabled()) {
        logger.debug(
            "Changing consumers from " + this.concurrentConsumers + " to " + concurrentConsumers);
      }
      int delta = this.concurrentConsumers - concurrentConsumers;
      this.concurrentConsumers = concurrentConsumers;
      if (isActive() && this.consumers != null) {
        if (delta > 0) {
          Iterator<Entry<BlockingQueueConsumer, Boolean>> entryIterator =
              consumers.entrySet().iterator();
          while (entryIterator.hasNext() && delta > 0) {
            Entry<BlockingQueueConsumer, Boolean> entry = entryIterator.next();
            if (entry.getValue()) {
              BlockingQueueConsumer consumer = entry.getKey();
              consumer.setQuiesce(this.shutdownTimeout);
              this.consumers.put(consumer, false);
              delta--;
            }
          }

        } else {
          addAndStartConsumers(-delta);
        }
      }
    }
  }