private Connection < CL > waitForConnection ( int timeout ) throws ConnectionException { Connection < CL > connection = null ; long startTime = System . currentTimeMillis ( ) ; try { blockedThreads . incrementAndGet ( ) ; connection = availableConnections . poll ( timeout , TimeUnit . MILLISECONDS ) ; if ( connection != null ) return connection ; throw new PoolTimeoutException ( "Timed out waiting for connection" ) . setHost ( getHost ( ) ) . setLatency ( System . currentTimeMillis ( ) - startTime ) ; } catch ( InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; throw new InterruptedOperationException ( "Thread interrupted waiting for connection" ) . setHost ( getHost ( ) ) . setLatency ( System . currentTimeMillis ( ) - startTime ) ; } finally { blockedThreads . decrementAndGet ( ) ; } }
Internal method to wait for a connection from the available connection pool .