/** Removes a connection */
  void removeItem(ManagedPoolItem item, ManagedConnection mConn) {
    synchronized (_connectionPool) {
      _idlePool.remove(mConn);

      _connectionPool.remove(item);
      _connectionPool.notifyAll();
    }

    try {
      item.destroy();
    } catch (Exception e) {
      log.log(Level.WARNING, e.toString(), e);
    }
  }
  /** Adds a connection to the idle pool. */
  void toIdle(ManagedPoolItem item) {
    try {
      if (_maxConnections < _connectionPool.size() || item.isConnectionError()) {
        return;
      }

      ManagedConnection mConn = item.getManagedConnection();

      if (mConn == null) {
        return;
      }

      mConn.cleanup();

      long now = CurrentTime.getCurrentTime();

      if (_idlePool.size() == 0) _idlePoolExpire = now + _idleTimeout;

      if (_idlePoolExpire < now) {
        // shrink the idle pool when non-empty for idleTimeout
        _idlePoolExpire = now + _idleTimeout;
      } else if (_idlePool.add(mConn)) {
        item = null;
        return;
      }
    } catch (Exception e) {
      log.log(Level.FINE, e.toString(), e);
    } finally {
      notifyConnectionAvailable();

      if (item != null) item.destroy();
    }
  }
  private void fillIdlePool() {
    int count = _minIdleCount;

    try {
      while (_connectionPool.size() < _minIdleCount && count-- >= 0 && _lifecycle.isActive()) {
        Subject subject = null;
        ConnectionRequestInfo info = null;

        UserPoolItem userPoolItem;

        userPoolItem = createConnection(_mcf, subject, info, null);

        if (userPoolItem != null) userPoolItem.toIdle();
      }
    } catch (Exception e) {
      e.printStackTrace();

      log.log(Level.FINE, e.toString(), e);
    }
  }