@ -25,6 +25,7 @@ import java.util.TimerTask;
import java.util.concurrent.ThreadPoolExecutor ;
import java.util.concurrent.TimeUnit ;
import java.util.concurrent.atomic.AtomicInteger ;
import java.util.concurrent.atomic.AtomicReference ;
import javax.sql.DataSource ;
@ -73,7 +74,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
private final String password ;
private volatile boolean isShutdown ;
private volatile long lastConnectionFailureTim e;
private volatile AtomicReference < Throwable > lastConnectionFailur e;
private int transactionIsolation ;
private boolean isDebug ;
@ -97,6 +98,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
this . connectionBag = new ConcurrentBag < IHikariConnectionProxy > ( ) ;
this . connectionBag . addBagStateListener ( this ) ;
this . isDebug = LOGGER . isDebugEnabled ( ) ;
this . lastConnectionFailure = new AtomicReference < Throwable > ( ) ;
this . catalog = configuration . getCatalog ( ) ;
this . connectionCustomizer = configuration . getConnectionCustomizer ( ) ;
@ -170,7 +172,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
while ( timeout > 0 ) ;
logPoolState ( "Timeout failure " ) ;
throw new SQLException ( String . format ( "Timeout of %dms encountered waiting for connection." , configuration . getConnectionTimeout ( ) ) );
throw new SQLException ( String . format ( "Timeout of %dms encountered waiting for connection." , configuration . getConnectionTimeout ( ) ) , lastConnectionFailure . getAndSet ( null ) );
}
catch ( InterruptedException e )
{
@ -252,6 +254,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
sleepBackoff = ( int ) Math . min ( 1000 f , ( ( float ) sleepBackoff ) * 1.5 ) ;
if ( getThreadsAwaitingConnection ( ) = = 0 )
{
lastConnectionFailure = null ;
break ;
}
continue ;
@ -347,6 +350,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
IHikariConnectionProxy proxyConnection = ProxyFactory . getProxyConnection ( this , connection , transactionIsolation , isAutoCommit , isReadOnly , catalog ) ;
proxyConnection . resetConnectionState ( ) ;
connectionBag . add ( proxyConnection ) ;
lastConnectionFailure . set ( null ) ;
return true ;
}
catch ( Exception e )
@ -359,12 +363,11 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
PoolUtilities . quietlyCloseConnection ( connection ) ;
}
long now = System . currentTimeMillis ( ) ;
if ( now - lastConnectionFailureTime > 1000 | | isDebug)
lastConnectionFailure . set ( e ) ;
if ( isDebug)
{
LOGGER . warn ( "Connection attempt to database {} failed (not every attempt is logged): {}" , configuration . getPoolName ( ) , e . getMessage ( ) , ( isDebug ? e : null ) ) ;
}
lastConnectionFailureTime = now ;
return false ;
}
}