Merge pull request #383 from nitincchauhan/dev

Fixes #379 stop retiring idle connections when minimumIdle is reached.
pull/384/head
Brett Wooldridge 10 years ago
commit 68225c20f1

@ -745,8 +745,6 @@ public class HikariConfig implements HikariConfigMXBean
public void validate()
{
Logger logger = LoggerFactory.getLogger(getClass());
validateNumerics();
if (poolName == null) {
@ -758,22 +756,22 @@ public class HikariConfig implements HikariConfigMXBean
}
if (driverClassName != null && jdbcUrl == null) {
logger.error("jdbcUrl is required with driverClassName");
LOGGER.error("jdbcUrl is required with driverClassName");
throw new IllegalArgumentException("jdbcUrl is required with driverClassName");
}
else if (driverClassName != null && dataSourceClassName != null) {
logger.error("cannot use driverClassName and dataSourceClassName together");
LOGGER.error("cannot use driverClassName and dataSourceClassName together");
throw new IllegalArgumentException("cannot use driverClassName and dataSourceClassName together");
}
else if (jdbcUrl != null) {
// OK
}
else if (dataSource == null && dataSourceClassName == null) {
logger.error("either dataSource or dataSourceClassName is required");
LOGGER.error("either dataSource or dataSourceClassName is required");
throw new IllegalArgumentException("either dataSource or dataSourceClassName is required");
}
else if (dataSource != null && dataSourceClassName != null) {
logger.warn("using dataSource and ignoring dataSourceClassName");
LOGGER.warn("using dataSource and ignoring dataSourceClassName");
}
if (transactionIsolationName != null) {
@ -787,8 +785,6 @@ public class HikariConfig implements HikariConfigMXBean
private void validateNumerics()
{
Logger logger = LoggerFactory.getLogger(getClass());
if (validationTimeout > connectionTimeout && connectionTimeout != Integer.MAX_VALUE) {
validationTimeout = connectionTimeout;
}
@ -798,29 +794,29 @@ public class HikariConfig implements HikariConfigMXBean
}
if (maxLifetime < 0) {
logger.error("maxLifetime cannot be negative.");
LOGGER.error("maxLifetime cannot be negative.");
throw new IllegalArgumentException("maxLifetime cannot be negative.");
}
else if (maxLifetime > 0 && maxLifetime < TimeUnit.SECONDS.toMillis(30)) {
logger.warn("maxLifetime is less than 30000ms, setting to default {}ms.", MAX_LIFETIME);
LOGGER.warn("maxLifetime is less than 30000ms, setting to default {}ms.", MAX_LIFETIME);
maxLifetime = MAX_LIFETIME;
}
if (idleTimeout != 0 && idleTimeout < TimeUnit.SECONDS.toMillis(10)) {
logger.warn("idleTimeout is less than 10000ms, setting to default {}ms.", IDLE_TIMEOUT);
LOGGER.warn("idleTimeout is less than 10000ms, setting to default {}ms.", IDLE_TIMEOUT);
idleTimeout = IDLE_TIMEOUT;
}
if (idleTimeout + TimeUnit.SECONDS.toMillis(1) > maxLifetime && maxLifetime > 0) {
logger.warn("idleTimeout is close to or greater than maxLifetime, disabling it.");
LOGGER.warn("idleTimeout is close to or greater than maxLifetime, disabling it.");
idleTimeout = 0;
}
if (maxLifetime == 0 && idleTimeout == 0) {
logger.warn("setting idleTimeout to {}ms.", IDLE_TIMEOUT);
LOGGER.warn("setting idleTimeout to {}ms.", IDLE_TIMEOUT);
idleTimeout = IDLE_TIMEOUT;
}
if (leakDetectionThreshold != 0 && leakDetectionThreshold < TimeUnit.SECONDS.toMillis(2) && !unitTest) {
logger.warn("leakDetectionThreshold is less than 2000ms, setting to minimum 2000ms.");
LOGGER.warn("leakDetectionThreshold is less than 2000ms, setting to minimum 2000ms.");
leakDetectionThreshold = 2000L;
}
}

@ -68,7 +68,7 @@ import com.zaxxer.hikari.util.PropertyElf;
*/
public class HikariPool implements HikariPoolMXBean, IBagStateListener
{
final Logger LOGGER = LoggerFactory.getLogger(getClass());
private static final Logger LOGGER = LoggerFactory.getLogger(HikariPool.class);
private static final ClockSource clockSource = ClockSource.INSTANCE;
@ -203,7 +203,7 @@ public class HikariPool implements HikariPoolMXBean, IBagStateListener
suspendResumeLock.release();
}
logPoolState("Timeout failure ");
logPoolState("Timeout failure\t");
String sqlState = null;
final Throwable originalException = lastConnectionFailure.getAndSet(null);
if (originalException instanceof SQLException) {
@ -241,7 +241,7 @@ public class HikariPool implements HikariPoolMXBean, IBagStateListener
poolState = POOL_SHUTDOWN;
LOGGER.info("{} - is closing down.", poolName);
logPoolState("Before closing ");
logPoolState("Before closing\t");
connectionBag.close();
softEvictConnections();
@ -271,7 +271,7 @@ public class HikariPool implements HikariPoolMXBean, IBagStateListener
closeConnectionExecutor.awaitTermination(5L, TimeUnit.SECONDS);
}
finally {
logPoolState("After closing ");
logPoolState("After closing\t");
poolElf.unregisterMBeans();
metricsTracker.close();
@ -526,7 +526,7 @@ public class HikariPool implements HikariPoolMXBean, IBagStateListener
addConnectionExecutor.execute(new Runnable() {
@Override
public void run() {
logPoolState("After fill ");
logPoolState("After fill\t");
}
});
}
@ -627,26 +627,22 @@ public class HikariPool implements HikariPoolMXBean, IBagStateListener
fillPool();
return;
}
else {
previous = now;
}
logPoolState("Before cleanup ");
logPoolState("Before cleanup\t");
final List<PoolBagEntry> bag = connectionBag.values(STATE_NOT_IN_USE);
int removable = bag.size() - config.getMinimumIdle();
for (PoolBagEntry bagEntry : bag) {
if (connectionBag.reserve(bagEntry)) {
if (removable > 0 && idleTimeout > 0L && clockSource.elapsedMillis(bagEntry.lastAccess, now) > idleTimeout) {
if (connectionBag.reserve(bagEntry)) {
closeConnection(bagEntry, "(connection passed idleTimeout)");
removable--;
}
else {
connectionBag.unreserve(bagEntry);
}
}
}
logPoolState("After cleanup ");
logPoolState("After cleanup\t");
fillPool(); // Try to maintain minimum connections
}

@ -94,7 +94,7 @@ public final class PoolBagEntry implements IConcurrentBagEntry
pool.closeConnection(PoolBagEntry.this, "(connection reached maxLifetime)");
}
else {
// else the connection is "in-use" and we mark it for eviction by pool.releaseConnection() or the housekeeper
// else the connection is "in-use" and we mark it for eviction by pool.releaseConnection()
PoolBagEntry.this.evicted = true;
}
}

@ -207,7 +207,7 @@ public final class PoolElf
* @param lastConnectionFailure last connection failure
* @return true if the connection is alive, false if it is not alive or we timed out
*/
boolean isConnectionAlive(final Connection connection, AtomicReference<Throwable> lastConnectionFailure)
boolean isConnectionAlive(final Connection connection, final AtomicReference<Throwable> lastConnectionFailure)
{
try {
int timeoutSec = (int) TimeUnit.MILLISECONDS.toSeconds(validationTimeout);

@ -31,6 +31,6 @@ public class PoolInitializationException extends RuntimeException
*/
public PoolInitializationException(Throwable t)
{
super("Exception during pool initialization", t);
super("Exception during pool initialization: " + t.getMessage(), t);
}
}

Loading…
Cancel
Save