When resetting the network timeout to its original value we can avoid an additional call to

getNetworkTimeout() by adding a specialized version of the method.
2.3.0
Brett Wooldridge 10 years ago
parent f97d66e554
commit 3fbcbf87b5

@ -373,7 +373,7 @@ public abstract class BaseHikariPool implements HikariPoolMBean, IBagStateListen
final boolean timeoutEnabled = (connectionTimeout != Integer.MAX_VALUE);
final long timeoutMs = timeoutEnabled ? Math.max(250L, connectionTimeout) : 0L;
final int originalTimeout = poolUtils.setNetworkTimeout(connection, timeoutMs, timeoutEnabled);
final int originalTimeout = poolUtils.getAndSetNetworkTimeout(connection, timeoutMs, timeoutEnabled);
transactionIsolation = (transactionIsolation < 0 ? connection.getTransactionIsolation() : transactionIsolation);

@ -174,17 +174,15 @@ public final class PoolUtilities
}
/**
* Set the network timeout, if <code>isUseNetworkTimeout</code> is <code>true</code>, and return the
* pre-existing value of the network timeout.
* Set the network timeout, if <code>isUseNetworkTimeout</code> is <code>true</code> and the
* driver supports it. Return the pre-existing value of the network timeout.
*
* @param executor an Executor
* @param connection the connection to set the network timeout on
* @param timeoutMs the number of milliseconds before timeout
* @param isUseNetworkTimeout true if the network timeout should be set, false otherwise
* @return the pre-existing network timeout value
* @throws SQLException thrown if the network timeout cannot be set
*/
public int setNetworkTimeout(final Connection connection, final long timeoutMs, final boolean isUseNetworkTimeout)
public int getAndSetNetworkTimeout(final Connection connection, final long timeoutMs, final boolean isUseNetworkTimeout)
{
if (isUseNetworkTimeout && isNetworkTimeoutSupported) {
try {
@ -201,6 +199,26 @@ public final class PoolUtilities
return 0;
}
/**
* Set the network timeout, if <code>isUseNetworkTimeout</code> is <code>true</code> and the
* driver supports it.
*
* @param connection the connection to set the network timeout on
* @param timeoutMs the number of milliseconds before timeout
* @param isUseNetworkTimeout true if the network timeout should be set, false otherwise
*/
public void setNetworkTimeout(final Connection connection, final long timeoutMs, final boolean isUseNetworkTimeout)
{
if (isUseNetworkTimeout && isNetworkTimeoutSupported) {
try {
connection.setNetworkTimeout(executorService, (int) timeoutMs);
}
catch (Throwable e) {
isNetworkTimeoutSupported = false;
}
}
}
/**
* Set the loginTimeout on the specified DataSource.
*

@ -160,7 +160,7 @@ public final class HikariPool extends BaseHikariPool
return connection.isValid(timeoutSec);
}
final int networkTimeout = poolUtils.setNetworkTimeout(connection, Math.max(1000, (int) timeoutMs), timeoutEnabled);
final int networkTimeout = poolUtils.getAndSetNetworkTimeout(connection, Math.max(1000, (int) timeoutMs), timeoutEnabled);
Statement statement = connection.createStatement();
try {

@ -144,7 +144,7 @@ public final class HikariPool extends BaseHikariPool
return connection.isValid(timeoutSec);
}
final int networkTimeout = poolUtils.setNetworkTimeout(connection, Math.max(1000, (int) timeoutMs), timeoutEnabled);
final int networkTimeout = poolUtils.getAndSetNetworkTimeout(connection, Math.max(1000, (int) timeoutMs), timeoutEnabled);
try (Statement statement = connection.createStatement()) {
poolUtils.setQueryTimeout(statement, timeoutSec);

Loading…
Cancel
Save