Restore max lifetime check to getConnection() rather than only in the

housekeeper thread.  An extremely active pool may never find an idle
connection in the housekeeper alone.
pull/60/head
Brett Wooldridge 11 years ago
parent cf2f0b0be4
commit f059d39aa6

@ -138,32 +138,34 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
Connection getConnection() throws SQLException
{
final long start = System.currentTimeMillis();
final long maxLife = configuration.getMaxLifetime();
final Context context = metricsTracker.recordConnectionRequest(start);
long timeout = configuration.getConnectionTimeout();
try
{
do
{
IHikariConnectionProxy connectionProxy = connectionBag.borrow(timeout, TimeUnit.MILLISECONDS);
if (connectionProxy == null) // We timed out... break and throw exception
IHikariConnectionProxy connection = connectionBag.borrow(timeout, TimeUnit.MILLISECONDS);
if (connection == null) // We timed out... break and throw exception
{
break;
}
connectionProxy.unclose();
connection.unclose();
if (System.currentTimeMillis() - connectionProxy.getLastAccess() > 1000 && !isConnectionAlive(connectionProxy, timeout))
final long now = System.currentTimeMillis();
if ((now - connection.getCreationTime() > maxLife) || (now - connection.getLastAccess() > 1000 && !isConnectionAlive(connection, timeout)))
{
closeConnection(connectionProxy); // Throw away the dead connection, try again
closeConnection(connection); // Throw away the dead connection, try again
timeout -= (System.currentTimeMillis() - start);
continue;
}
else if (leakDetectionThreshold > 0)
{
connectionProxy.captureStack(leakDetectionThreshold, houseKeepingTimer);
connection.captureStack(leakDetectionThreshold, houseKeepingTimer);
}
return connectionProxy;
return connection;
}
while (timeout > 0);

Loading…
Cancel
Save