fix: the timing of obtaining the number of waiting threads in the connection pool is wrong

This commit is contained in:
guoaomen
2023-05-08 10:45:18 +08:00
parent 4f1326d91b
commit 9553c77b2e
2 changed files with 7 additions and 2 deletions

View File

@@ -80,9 +80,10 @@ public class ConnectionPool extends PoolBase implements PooledConnectionListener
try {
ConnectionPoolProvider.getConnGetFrenshLocekAfter();
ConnectionPoolProvider.borrowDirectlyConnectionBefore();
int waiting = waiters.get();
for (PooledConnection conn : allConnections) {
if (conn.compareAndSet(STATE_NOT_IN_USE, STATE_IN_USE)) {
final int waiting = waiterNum;
ConnectionPoolProvider.getWaiterCountAfter();
if (waiting > 0 && conn.getCreateByWaiter().compareAndSet(true, false)) {
ConnectionPoolProvider.newConnectionBorrowDirectly();
newPooledEntry(schema, waiting, true);
@@ -102,12 +103,12 @@ public class ConnectionPool extends PoolBase implements PooledConnectionListener
freshLock.readLock().lock();
}
try {
final int waiting = waiterNum;
ConnectionPoolProvider.getConnGetFrenshLocekAfter();
ConnectionPoolProvider.borrowConnectionBefore();
for (PooledConnection conn : allConnections) {
if (conn.compareAndSet(STATE_NOT_IN_USE, STATE_IN_USE)) {
// If we may have stolen another waiter's connection, request another bag add.
final int waiting = waiterNum;
if (waiting > 0 && conn.getCreateByWaiter().compareAndSet(true, false)) {
ConnectionPoolProvider.newConnectionBorrow0();
newPooledEntry(schema, waiting, true);

View File

@@ -51,5 +51,9 @@ public final class ConnectionPoolProvider {
}
public static void getWaiterCountAfter() {
}
}