|
|
|
@ -93,6 +93,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
|
|
|
|
|
|
|
|
|
|
private volatile boolean isShutdown;
|
|
|
|
|
private volatile long connectionTimeout;
|
|
|
|
|
private volatile boolean isJdbc41Compliant;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Construct a HikariPool with the specified configuration.
|
|
|
|
@ -368,11 +369,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
|
|
|
|
|
@Override
|
|
|
|
|
public void closeIdleConnections()
|
|
|
|
|
{
|
|
|
|
|
connectionBag.values(STATE_NOT_IN_USE).forEach(bagEntry -> {
|
|
|
|
|
if (connectionBag.reserve(bagEntry)) {
|
|
|
|
|
closeConnection(bagEntry);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
connectionBag.values(STATE_NOT_IN_USE).stream().filter(p -> connectionBag.reserve(p)).forEach(bagEntry -> closeConnection(bagEntry));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */
|
|
|
|
@ -414,10 +411,10 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
|
|
|
|
|
|
|
|
|
|
Connection connection = null;
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
connection = (username == null && password == null) ? dataSource.getConnection() : dataSource.getConnection(username, password);
|
|
|
|
|
transactionIsolation = (transactionIsolation < 0 ? connection.getTransactionIsolation() : transactionIsolation);
|
|
|
|
|
connectionCustomizer.customize(connection);
|
|
|
|
|
isJdbc41Compliant = PoolUtilities.isJdbc41Compliant(connection);
|
|
|
|
|
|
|
|
|
|
executeSqlAutoCommit(connection, configuration.getConnectionInitSql());
|
|
|
|
|
|
|
|
|
@ -462,19 +459,28 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
|
|
|
|
|
return connection.isValid((int) TimeUnit.MILLISECONDS.toSeconds(timeoutMs));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int networkTimeout = 0;
|
|
|
|
|
if (isJdbc41Compliant) {
|
|
|
|
|
networkTimeout = connection.getNetworkTimeout();
|
|
|
|
|
connection.setNetworkTimeout(houseKeepingExecutorService, timeoutEnabled ? (int) timeoutMs : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try (Statement statement = connection.createStatement()) {
|
|
|
|
|
statement.setQueryTimeout((int) TimeUnit.MILLISECONDS.toSeconds(timeoutMs));
|
|
|
|
|
statement.executeQuery(configuration.getConnectionTestQuery());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
if (isIsolateInternalQueries && !isAutoCommit) {
|
|
|
|
|
connection.rollback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isIsolateInternalQueries && !isAutoCommit) {
|
|
|
|
|
connection.rollback();
|
|
|
|
|
}
|
|
|
|
|
if (isJdbc41Compliant) {
|
|
|
|
|
connection.setNetworkTimeout(houseKeepingExecutorService, networkTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (SQLException e) {
|
|
|
|
|
LOGGER.warn("Exception during keep alive check, that means the connection (" + connection + ") must be dead.", e);
|
|
|
|
|
LOGGER.warn("Exception during keep alive check, that means the connection ({}) must be dead.", connection, e);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|