|
1 | 1 | /*
|
2 |
| - * Copyright 2009-2024 the original author or authors. |
| 2 | + * Copyright 2009-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -389,11 +389,10 @@ private int assembleConnectionTypeCode(String url, String username, String passw
|
389 | 389 | }
|
390 | 390 |
|
391 | 391 | protected void pushConnection(PooledConnection conn) throws SQLException {
|
392 |
| - |
393 | 392 | lock.lock();
|
394 | 393 | try {
|
395 |
| - state.activeConnections.remove(conn); |
396 | 394 | if (conn.isValid()) {
|
| 395 | + state.activeConnections.remove(conn); |
397 | 396 | if (state.idleConnections.size() < poolMaximumIdleConnections
|
398 | 397 | && conn.getConnectionTypeCode() == expectedConnectionTypeCode) {
|
399 | 398 | state.accumulatedCheckoutTime += conn.getCheckoutTime();
|
@@ -441,17 +440,19 @@ private PooledConnection popConnection(String username, String password) throws
|
441 | 440 | while (conn == null) {
|
442 | 441 | lock.lock();
|
443 | 442 | try {
|
444 |
| - if (!state.idleConnections.isEmpty()) { |
445 |
| - // Pool has available connection |
446 |
| - conn = state.idleConnections.remove(0); |
447 |
| - if (log.isDebugEnabled()) { |
448 |
| - log.debug("Checked out connection " + conn.getRealHashCode() + " from pool."); |
449 |
| - } |
450 |
| - } else if (state.activeConnections.size() < poolMaximumActiveConnections) { |
451 |
| - // Pool does not have available connection and can create a new connection |
452 |
| - conn = new PooledConnection(dataSource.getConnection(), this); |
453 |
| - if (log.isDebugEnabled()) { |
454 |
| - log.debug("Created connection " + conn.getRealHashCode() + "."); |
| 443 | + if (state.activeConnections.size() < poolMaximumActiveConnections) { |
| 444 | + if (!state.idleConnections.isEmpty()) { |
| 445 | + // Pool has available connection |
| 446 | + conn = state.idleConnections.remove(0); |
| 447 | + if (log.isDebugEnabled()) { |
| 448 | + log.debug("Checked out connection " + conn.getRealHashCode() + " from pool."); |
| 449 | + } |
| 450 | + } else { |
| 451 | + // Pool does not have available connection and can create a new connection |
| 452 | + conn = new PooledConnection(dataSource.getConnection(), this); |
| 453 | + if (log.isDebugEnabled()) { |
| 454 | + log.debug("Created connection " + conn.getRealHashCode() + "."); |
| 455 | + } |
455 | 456 | }
|
456 | 457 | } else {
|
457 | 458 | // Cannot create new connection
|
|
0 commit comments