private RealConnection findHealthyConnection ( int connectTimeout , int readTimeout , int writeTimeout , int pingIntervalMillis , boolean connectionRetryEnabled , boolean doExtensiveHealthChecks ) throws IOException { while ( true ) { RealConnection candidate = findConnection ( connectTimeout , readTimeout , writeTimeout , pingIntervalMillis , connectionRetryEnabled ) ; // If this is a brand new connection, we can skip the extensive health checks. synchronized ( connectionPool ) { if ( candidate . successCount == 0 ) { return candidate ; } } // Do a (potentially slow) check to confirm that the pooled connection is still good. If it // isn't, take it out of the pool and start again. if ( ! candidate . isHealthy ( doExtensiveHealthChecks ) ) { candidate . noNewExchanges ( ) ; continue ; } return candidate ; } }
Finds a connection and returns it if it is healthy . If it is unhealthy the process is repeated until a healthy connection is found .