Skip to content

Commit

Permalink
implemented suggestion from 379
Browse files Browse the repository at this point in the history
  • Loading branch information
nitincchauhan committed Aug 13, 2015
1 parent 265ee41 commit 1137ed1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/main/java/com/zaxxer/hikari/pool/HikariPool.java
Expand Up @@ -25,6 +25,7 @@
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLTransientConnectionException;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
Expand Down Expand Up @@ -490,7 +491,7 @@ private boolean addConnection()
String username = config.getUsername();
String password = config.getPassword();

connection = (username == null && password == null) ? dataSource.getConnection() : dataSource.getConnection(username, password);
connection = (username == null) ? dataSource.getConnection() : dataSource.getConnection(username, password);
poolElf.setupConnection(connection, connectionTimeout);

connectionBag.add(new PoolBagEntry(connection, this));
Expand Down Expand Up @@ -630,13 +631,18 @@ public void run()
}

logPoolState("Before cleanup ");
for (PoolBagEntry bagEntry : connectionBag.values(STATE_NOT_IN_USE)) {
final int minIdle = config.getMinimumIdle();
final List<PoolBagEntry> bag = connectionBag.values(STATE_NOT_IN_USE);
int totIdle = bag.size();
for (PoolBagEntry bagEntry : bag) {
if (connectionBag.reserve(bagEntry)) {
if (bagEntry.evicted) {
closeConnection(bagEntry, "(connection evicted)");
totIdle --;
}
else if (idleTimeout > 0L && clockSource.elapsedMillis(bagEntry.lastAccess, now) > idleTimeout) {
else if (totIdle > minIdle && idleTimeout > 0L && clockSource.elapsedMillis(bagEntry.lastAccess, now) > idleTimeout) {
closeConnection(bagEntry, "(connection passed idleTimeout)");
totIdle --;
}
else {
connectionBag.unreserve(bagEntry);
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/zaxxer/hikari/pool/PoolElf.java
Expand Up @@ -217,11 +217,12 @@ boolean isConnectionAlive(final Connection connection, AtomicReference<Throwable
}

final int originalTimeout = getAndSetNetworkTimeout(connection, validationTimeout);

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

statement.execute(config.getConnectionTestQuery());
}

Expand Down

0 comments on commit 1137ed1

Please sign in to comment.