Skip to content

Commit 3f96b26

Browse files
committed
Fixed bug closing unused connections in the ConnectionPool
1 parent 7c94198 commit 3f96b26

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/javaxt/sql/ConnectionPool.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,17 @@ private Connection getRecycledConnection() throws SQLException {
457457

458458
PooledConnection pconn = wrapper.pooledConnection;
459459

460-
// Skip all validation for very recently recycled connections (< 5 seconds)
460+
// Check if this is a warm-up connection that was never opened
461+
boolean isWarmupConnection =
462+
(wrapper.lastUsedTime == wrapper.createdTime && wrapper.connection.getConnection() == null);
463+
464+
// Check if the connection was recently recycled (< 5 seconds)
465+
boolean connectionIsStale = (System.currentTimeMillis() - wrapper.lastUsedTime) > 5000;
466+
467+
// Skip validation for very recently recycled connections (< 5 seconds)
461468
// This dramatically improves performance for high-frequency connection reuse scenarios
462-
boolean validateConnection = (System.currentTimeMillis() - wrapper.lastUsedTime) > 5000;
463-
if (validateConnection) {
469+
if (!isWarmupConnection && connectionIsStale) {
470+
464471
// Standard validation path for older connections
465472
boolean needsValidation = wrapper.isExpired(connectionMaxAgeMs) ||
466473
wrapper.isIdle(connectionIdleTimeoutMs) ||

0 commit comments

Comments
 (0)