@ Override public Connection < CL > borrowConnection ( int timeout ) throws ConnectionException { Connection < CL > connection = null ; long startTime = System . currentTimeMillis ( ) ; try { // Try to get a free connection without blocking. connection = availableConnections . poll ( ) ; if ( connection != null ) { return connection ; } boolean isOpenning = tryOpenAsync ( ) ; // Wait for a connection to free up or a new one to be opened if ( timeout > 0 ) { connection = waitForConnection ( isOpenning ? config . getConnectTimeout ( ) : timeout ) ; return connection ; } else throw new PoolTimeoutException ( "Fast fail waiting for connection from pool" ) . setHost ( getHost ( ) ) . setLatency ( System . currentTimeMillis ( ) - startTime ) ; } finally { if ( connection != null ) { borrowedCount . incrementAndGet ( ) ; monitor . incConnectionBorrowed ( host , System . currentTimeMillis ( ) - startTime ) ; } } }
Create a connection as long the max hasn t been reached