Skip to content

Commit

Permalink
tweak isConnectionAlive and few other
Browse files Browse the repository at this point in the history
  • Loading branch information
nitincchauhan committed Aug 11, 2015
1 parent e789d03 commit 265ee41
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/main/java/com/zaxxer/hikari/pool/HikariPool.java
Expand Up @@ -242,9 +242,7 @@ public final synchronized void shutdown() throws InterruptedException
LOGGER.info("{} - is closing down.", poolName);
logPoolState("Before closing ");

connectionBag.close();
softEvictConnections();
addConnectionExecutor.shutdownNow();
addConnectionExecutor.shutdown();
addConnectionExecutor.awaitTermination(5L, TimeUnit.SECONDS);
if (config.getScheduledExecutorService() == null) {
houseKeepingExecutorService.shutdown();
Expand All @@ -253,6 +251,7 @@ public final synchronized void shutdown() throws InterruptedException

final ExecutorService assassinExecutor = createThreadPoolExecutor(config.getMaximumPoolSize(), "Hikari connection assassin",
config.getThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy());
connectionBag.close();
try {
final long start = clockSource.currentTime();
do {
Expand Down Expand Up @@ -365,7 +364,7 @@ public void run()
while (poolState == POOL_NORMAL && totalConnections.get() < maxPoolSize && getIdleConnections() <= minimumIdle && !addConnection()) {
// If we got into the loop, addConnection() failed, so we sleep and retry
quietlySleep(sleepBackoff);
sleepBackoff = Math.min(connectionTimeout / 2, (long) ((double) sleepBackoff * 1.5));
sleepBackoff = Math.min((long) (connectionTimeout / 2), (long) (sleepBackoff * 1.5));
}
}
}, true);
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/zaxxer/hikari/pool/PoolBagEntry.java
Expand Up @@ -182,8 +182,10 @@ public boolean compareAndSet(int expect, int update)
@Override
public String toString()
{
return String.format("%s (created %s, last release %dms ago, %s)",
connection, formatDateTime(creationTime), ClockSource.INSTANCE.elapsedMillis(lastAccess), stateToString());
return connection
+ ", created " + formatDateTime(creationTime)
+ ", last release " + ClockSource.INSTANCE.elapsedMillis(lastAccess) + "ms ago, "
+ stateToString();
}

void close()
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/zaxxer/hikari/pool/PoolElf.java
Expand Up @@ -219,7 +219,9 @@ boolean isConnectionAlive(final Connection connection, AtomicReference<Throwable
final int originalTimeout = getAndSetNetworkTimeout(connection, validationTimeout);

try (Statement statement = connection.createStatement()) {
setQueryTimeout(statement, timeoutSec);
if (isNetworkTimeoutSupported != TRUE) {
setQueryTimeout(statement, timeoutSec);
}
statement.execute(config.getConnectionTestQuery());
}

Expand Down

0 comments on commit 265ee41

Please sign in to comment.