DataSource.setLoginTimeout() is in seconds. Make sure the milliseconds passed in to addConnection(timeout) is converted to seconds. Also add a validation to prevent sub-second retries that would be converted to 0 when performing a millisecond to second conversion using TimeUnit.

pull/60/head
Brett Wooldridge 11 years ago
parent 27cd322fba
commit 3c20da2751

@ -586,7 +586,7 @@ public class HikariConfig implements HikariConfigMBean
{
logger.warn("No connection wait timeout is set, this might cause an infinite wait.");
}
else if (connectionTimeout < 100)
else if (connectionTimeout < TimeUnit.MILLISECONDS.toMillis(100))
{
logger.warn("connectionTimeout is less than 100ms, did you specify the wrong time unit? Using default instead.");
connectionTimeout = CONNECTION_TIMEOUT;
@ -612,7 +612,7 @@ public class HikariConfig implements HikariConfigMBean
logger.error("idleTimeout cannot be negative.");
throw new IllegalStateException("idleTimeout cannot be negative.");
}
else if (idleTimeout < 30000 && idleTimeout != 0)
else if (idleTimeout < TimeUnit.SECONDS.toMillis(30) && idleTimeout != 0)
{
logger.warn("idleTimeout is less than 30000ms, did you specify the wrong time unit? Using default instead.");
idleTimeout = IDLE_TIMEOUT;
@ -624,7 +624,7 @@ public class HikariConfig implements HikariConfigMBean
throw new IllegalStateException("Either jdbc4ConnectionTest must be enabled or a connectionTestQuery must be specified.");
}
if (leakDetectionThreshold != 0 && leakDetectionThreshold < 10000)
if (leakDetectionThreshold != 0 && leakDetectionThreshold < TimeUnit.SECONDS.toMillis(10))
{
logger.warn("leakDetectionThreshold is less than 10000ms, did you specify the wrong time unit? Disabling leak detection.");
leakDetectionThreshold = 0;
@ -641,12 +641,24 @@ public class HikariConfig implements HikariConfigMBean
logger.error("maxLifetime cannot be negative.");
throw new IllegalStateException("maxLifetime cannot be negative.");
}
else if (maxLifetime < 120000 && maxLifetime != 0)
else if (maxLifetime < TimeUnit.SECONDS.toMillis(120) && maxLifetime != 0)
{
logger.warn("maxLifetime is less than 120000ms, did you specify the wrong time unit? Using default instead.");
maxLifetime = MAX_LIFETIME;
}
if (acquireRetries > 0 && connectionTimeout > 0)
{
long retryTimeoutMs = (connectionTimeout / (acquireRetries + 1));
if (retryTimeoutMs < TimeUnit.SECONDS.toMillis(1))
{
logger.warn("JDBC setLoginTimeout() has a minimum resolution of 1 second, but requested acquireRetries({})" +
"in connectionTimeout({}ms) would result in sub-second values. Using {}ms for connectionTimeout instead.",
acquireRetries, connectionTimeout, TimeUnit.SECONDS.toMillis(acquireRetries));
connectionTimeout = TimeUnit.SECONDS.toMillis(acquireRetries);
}
}
if (transactionIsolationName != null)
{
try

@ -209,7 +209,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
@Override
public void addBagItem(long timeout)
{
addConnection(timeout);
addConnection(TimeUnit.MILLISECONDS.toSeconds(timeout));
}
// ***********************************************************************

@ -72,6 +72,9 @@ public class ConcurrentBag<T extends com.zaxxer.hikari.util.ConcurrentBag.IBagMa
*/
public interface IBagStateListener
{
/**
* @param timeout timeout to add item to bag in milliseconds
*/
void addBagItem(long timeout);
}
@ -120,7 +123,7 @@ public class ConcurrentBag<T extends com.zaxxer.hikari.util.ConcurrentBag.IBagMa
}
// Otherwise, scan the shared list ... for maximum of timeoutMillis
final long retryTimeoutMs = (retries > 0 && timeoutMillis > 0) ? Math.max((timeoutMillis / (retries + 1)), 100) : timeoutMillis;
final long retryTimeoutMs = (retries > 0 && timeoutMillis > 0) ? Math.max((timeoutMillis / (retries + 1)), 1000) : timeoutMillis;
long totalTimeoutNs = TimeUnit.MILLISECONDS.toNanos(timeoutMillis);
boolean tryAddItem = true;
while (totalTimeoutNs > 0)

Loading…
Cancel
Save