private void removeIdleTimeoutConnection() {

    //descending iterator since first from queue are the first to be used
    Iterator<MariaDbPooledConnection> iterator = idleConnections.descendingIterator();

    MariaDbPooledConnection item;

    while (iterator.hasNext()) {
      item = iterator.next();

      long idleTime = System.nanoTime() - item.getLastUsed().get();
      boolean timedOut = idleTime > TimeUnit.SECONDS.toNanos(maxIdleTime);

      boolean shouldBeReleased = false;

      if (globalInfo != null) {

        // idle time is reaching server @@wait_timeout
        if (idleTime > TimeUnit.SECONDS.toNanos(globalInfo.getWaitTimeout() - 45)) {
          shouldBeReleased = true;
        }

        //  idle has reach option maxIdleTime value and pool has more connections than minPoolSiz
        if (timedOut && totalConnection.get() > options.minPoolSize) {
          shouldBeReleased = true;
        }

      } else if (timedOut) {
        shouldBeReleased = true;
      }

      if (shouldBeReleased && idleConnections.remove(item)) {

        totalConnection.decrementAndGet();
        silentCloseConnection(item);
        addConnectionRequest();
        if (logger.isDebugEnabled()) {
          logger.debug(
              "pool {} connection removed due to inactivity (total:{}, active:{}, pending:{})",
              poolTag, totalConnection.get(), getActiveConnections(), pendingRequestNumber.get());
        }

      }
    }

  }
private void removeIdleTimeoutConnection ( ) { Iterator < MariaDbPooledConnection > iterator = idleConnections . descendingIterator ( ) ; MariaDbPooledConnection item ; while ( iterator . hasNext ( ) ) { item = iterator . next ( ) ; long idleTime = System . nanoTime ( ) - item . getLastUsed ( ) . get ( ) ; boolean timedOut = idleTime > TimeUnit . SECONDS . toNanos ( maxIdleTime ) ; boolean shouldBeReleased = false ; if ( globalInfo != null ) { if ( idleTime > TimeUnit . SECONDS . toNanos ( globalInfo . getWaitTimeout ( ) - 45 ) ) { shouldBeReleased = true ; } if ( timedOut && totalConnection . get ( ) > options . minPoolSize ) { shouldBeReleased = true ; } } else if ( timedOut ) { shouldBeReleased = true ; } if ( shouldBeReleased && idleConnections . remove ( item ) ) { totalConnection . decrementAndGet ( ) ; silentCloseConnection ( item ) ; addConnectionRequest ( ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "pool {} connection removed due to inactivity (total:{}, active:{}, pending:{})" , poolTag , totalConnection . get ( ) , getActiveConnections ( ) , pendingRequestNumber . get ( ) ) ; } } } }
Removing idle connection.
Close them and recreate connection to reach minimal number of connection.