From 10dd8cad2c7e72c4959a27ff06e7d062cf6ba335 Mon Sep 17 00:00:00 2001 From: pony Date: Thu, 24 May 2018 17:17:19 +0800 Subject: [PATCH] =?UTF-8?q?BI-22377=20druid=E5=8A=A0=E4=B8=8A-DfrDruidLogA?= =?UTF-8?q?ctiveCount=3Dtrue=E5=8F=AF=E6=89=93=E5=8D=B0activecount?= =?UTF-8?q?=E7=9A=84=E5=A0=86=E6=A0=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alibaba/druid/pool/DruidDataSource.java | 85 +++++++++++-------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSource.java b/fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSource.java index eec487950..e58893b67 100644 --- a/fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSource.java +++ b/fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSource.java @@ -15,42 +15,6 @@ */ package com.fr.third.alibaba.druid.pool; -import java.io.Closeable; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.ConcurrentModificationException; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.ServiceLoader; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -import javax.management.JMException; -import javax.management.MBeanRegistration; -import javax.management.MBeanServer; -import javax.management.ObjectName; -import javax.naming.NamingException; -import javax.naming.Reference; -import javax.naming.Referenceable; -import javax.naming.StringRefAddr; -import javax.sql.ConnectionEvent; -import javax.sql.ConnectionEventListener; -import javax.sql.ConnectionPoolDataSource; -import javax.sql.PooledConnection; - import com.fr.third.alibaba.druid.Constants; import com.fr.third.alibaba.druid.TransactionTimeoutException; import com.fr.third.alibaba.druid.VERSION; @@ -94,6 +58,41 @@ import com.fr.third.alibaba.druid.util.Utils; import com.fr.third.alibaba.druid.wall.WallFilter; import com.fr.third.alibaba.druid.wall.WallProviderStatValue; +import javax.management.JMException; +import javax.management.MBeanRegistration; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.naming.NamingException; +import javax.naming.Reference; +import javax.naming.Referenceable; +import javax.naming.StringRefAddr; +import javax.sql.ConnectionEvent; +import javax.sql.ConnectionEventListener; +import javax.sql.ConnectionPoolDataSource; +import javax.sql.PooledConnection; +import java.io.Closeable; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.ConcurrentModificationException; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.ServiceLoader; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + /** * @author ljw [ljw2083@alibaba-inc.com] * @author wenshao [szujobs@hotmail.com] @@ -167,6 +166,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat private volatile boolean keepAlive = false; + private static final boolean logActiveCount = "true".equals(System.getProperty("frDruidLogActiveCount")); + public DruidDataSource(){ this(false); } @@ -1166,6 +1167,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat lock.lock(); try { activeCount--; + logActiveCount(false); discardCount++; if (activeCount <= minIdle) { @@ -1217,6 +1219,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat if (holder != null) { activeCount++; + logActiveCount(true); if (activeCount > activePeak) { activePeak = activeCount; activePeakTime = System.currentTimeMillis(); @@ -1406,6 +1409,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat lock.lock(); try { activeCount--; + logActiveCount(false); closeCount++; } finally { lock.unlock(); @@ -1424,6 +1428,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat lock.lockInterruptibly(); try { activeCount--; + logActiveCount(false); closeCount++; result = putLast(holder, lastActiveTimeMillis); @@ -3124,4 +3129,12 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat public boolean isClosed() { return this.closed; } + + private void logActiveCount(boolean isIncrease){ + if (logActiveCount){ + System.out.println("activeCount " + (isIncrease ? "increase" : "decrease")); + System.out.println("current count is " + activeCount); + new Throwable().printStackTrace(); + } + } }