/** 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(); } }
/* * Removes a connection from the pool. */ public void markForPoolRemoval(ManagedConnection mConn) { synchronized (_connectionPool) { for (int i = _connectionPool.size() - 1; i >= 0; i--) { ManagedPoolItem poolItem = _connectionPool.get(i); if (poolItem.getManagedConnection() == mConn) { poolItem.setConnectionError(); return; } } } }
private ManagedPoolItem findPoolItem(ManagedConnection mConn) { synchronized (_connectionPool) { for (int i = _connectionPool.size() - 1; i >= 0; i--) { ManagedPoolItem testPoolItem = _connectionPool.get(i); if (testPoolItem.getManagedConnection() == mConn) { return testPoolItem; } } return null; } }