Skip to content

Commit

Permalink
fix max active control algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
zrlw authored and wenshao committed Nov 26, 2023
1 parent daf78fa commit bbab769
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,7 @@ private DruidPooledConnection getConnectionInternal(long maxWait) throws SQLExce
long startTime = System.currentTimeMillis(); //进入循环等待之前,先记录开始尝试获取连接的时间
for (boolean createDirect = false; ; ) {
if (createDirect) {
createDirect = false;
createStartNanosUpdater.set(this, System.nanoTime());
if (creatingCountUpdater.compareAndSet(this, 0, 1)) {
PhysicalConnectionInfo pyConnInfo = DruidDataSource.this.createPhysicalConnection();
Expand All @@ -1709,7 +1710,7 @@ private DruidPooledConnection getConnectionInternal(long maxWait) throws SQLExce
final Lock lock = this.lock;
lock.lock();
try {
if (activeCount < maxActive) {
if (activeCount + poolingCount < maxActive) {
activeCount++;
holder.active = true;
if (activeCount > activePeak) {
Expand Down Expand Up @@ -2305,7 +2306,7 @@ public boolean isMbeanRegistered() {
}

boolean putLast(DruidConnectionHolder e, long lastActiveTimeMillis) {
if (poolingCount >= maxActive || e.discard || this.closed || this.closing) {
if (activeCount + poolingCount >= maxActive || e.discard || this.closed || this.closing) {
return false;
}

Expand Down Expand Up @@ -2670,7 +2671,7 @@ private boolean put(DruidConnectionHolder holder, long createTaskId, boolean che
return false;
}

if (poolingCount >= maxActive) {
if (activeCount + poolingCount >= maxActive) {
if (createScheduler != null) {
clearCreateTask(createTaskId);
}
Expand Down

0 comments on commit bbab769

Please sign in to comment.