Browse Source

Merge pull request #53 in CORE/base-third from release/9.0 to master

* commit '80f7f6231077b33da7e3156551bfad3a3a8a092b':
  改用logger
  BI-22377 druid加上-DfrDruidLogActiveCount=true可打印activecount的堆栈
master
superman 7 years ago
parent
commit
50392d934a
  1. 83
      fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSource.java

83
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,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
public boolean isClosed() {
return this.closed;
}
private void logActiveCount(boolean isIncrease){
if (logActiveCount){
LOG.debug("activeCount " + (isIncrease ? "increase" : "decrease") + "current count is : " + activeCount, new Throwable());
}
}
}

Loading…
Cancel
Save