code: public void setMaxConnections(int maxConnections) {
          int adjustment;
          lock.lock();
          try {
              this.maxConnections = maxConnections;
              if (!isRunning()) return;
          } finally {
              lock.unlock();
          }
          // We may now have too many or too few open connections. Add more or drop some to get to the right amount.
          adjustment = maxConnections - channels.getConnectedClientCount();
          if (adjustment > 0)
              triggerConnections();
  
          if (adjustment < 0)
              channels.closeConnections(-adjustment);
      }
docs: Adjusts the desired number of connections that we will create to peers. Note that if there are already peers
  open and the new value is lower than the current number of peers, those connections will be terminated. Likewise
  if there aren't enough current connections to meet the new requested max size, some will be added.