sleep reasonably, fix possible negative lifetime

pull/502/head
Nitin 9 years ago
parent cfd5e4d054
commit 8eaaa7fdcd

@ -438,7 +438,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
final long maxLifetime = config.getMaxLifetime(); final long maxLifetime = config.getMaxLifetime();
if (maxLifetime > 0) { if (maxLifetime > 0) {
// variance up to 2.5% of the maxlifetime // variance up to 2.5% of the maxlifetime
final long variance = maxLifetime > 10_000 ? ThreadLocalRandom.current().nextLong( Math.max(10_000, maxLifetime / 40) ) : 0; final long variance = maxLifetime > 10_000 ? ThreadLocalRandom.current().nextLong( maxLifetime / 40 ) : 0;
final long lifetime = maxLifetime - variance; final long lifetime = maxLifetime - variance;
poolEntry.setFutureEol(houseKeepingExecutorService.schedule(new Runnable() { poolEntry.setFutureEol(houseKeepingExecutorService.schedule(new Runnable() {
@Override @Override
@ -573,7 +573,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
// failed to get connection from db, sleep and retry // failed to get connection from db, sleep and retry
quietlySleep(sleepBackoff); quietlySleep(sleepBackoff);
sleepBackoff = Math.min(connectionTimeout / 2, (long) (sleepBackoff * 1.3)); sleepBackoff = Math.min(connectionTimeout / 4, (long) (sleepBackoff * 1.3));
} }
// Pool is suspended or shutdown or at max size // Pool is suspended or shutdown or at max size
return Boolean.FALSE; return Boolean.FALSE;

Loading…
Cancel
Save