private void discardIdleConnections ( ) { List < Connection < CL >> connections = Lists . newArrayList ( ) ; availableConnections . drainTo ( connections ) ; activeCount . addAndGet ( - connections . size ( ) ) ; for ( Connection < CL > connection : connections ) { try { closedConnections . incrementAndGet ( ) ; connection . close ( ) ; // This is usually an async operation } catch ( Throwable t ) { // TODO } } }
Drain all idle connections and close them . Connections that are currently borrowed will not be closed here .