|
|
@ -15,42 +15,6 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package com.fr.third.alibaba.druid.pool; |
|
|
|
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.Constants; |
|
|
|
import com.fr.third.alibaba.druid.TransactionTimeoutException; |
|
|
|
import com.fr.third.alibaba.druid.TransactionTimeoutException; |
|
|
|
import com.fr.third.alibaba.druid.VERSION; |
|
|
|
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.WallFilter; |
|
|
|
import com.fr.third.alibaba.druid.wall.WallProviderStatValue; |
|
|
|
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 ljw [ljw2083@alibaba-inc.com] |
|
|
|
* @author wenshao [szujobs@hotmail.com] |
|
|
|
* @author wenshao [szujobs@hotmail.com] |
|
|
@ -167,6 +166,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat |
|
|
|
|
|
|
|
|
|
|
|
private volatile boolean keepAlive = false; |
|
|
|
private volatile boolean keepAlive = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final boolean logActiveCount = "true".equals(System.getProperty("frDruidLogActiveCount")); |
|
|
|
|
|
|
|
|
|
|
|
public DruidDataSource(){ |
|
|
|
public DruidDataSource(){ |
|
|
|
this(false); |
|
|
|
this(false); |
|
|
|
} |
|
|
|
} |
|
|
@ -828,7 +829,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* load filters from SPI ServiceLoader |
|
|
|
* load filters from SPI ServiceLoader |
|
|
|
* |
|
|
|
* |
|
|
|
* @see ServiceLoader |
|
|
|
* @see ServiceLoader |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void initFromSPIServiceLoader() { |
|
|
|
private void initFromSPIServiceLoader() { |
|
|
@ -873,7 +874,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 会去重复 |
|
|
|
* 会去重复 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param filter |
|
|
|
* @param filter |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void addFilter(Filter filter) { |
|
|
|
private void addFilter(Filter filter) { |
|
|
@ -1157,7 +1158,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 抛弃连接,不进行回收,而是抛弃 |
|
|
|
* 抛弃连接,不进行回收,而是抛弃 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param realConnection |
|
|
|
* @param realConnection |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void discardConnection(Connection realConnection) { |
|
|
|
public void discardConnection(Connection realConnection) { |
|
|
@ -1166,6 +1167,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat |
|
|
|
lock.lock(); |
|
|
|
lock.lock(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
activeCount--; |
|
|
|
activeCount--; |
|
|
|
|
|
|
|
logActiveCount(false); |
|
|
|
discardCount++; |
|
|
|
discardCount++; |
|
|
|
|
|
|
|
|
|
|
|
if (activeCount <= minIdle) { |
|
|
|
if (activeCount <= minIdle) { |
|
|
@ -1217,6 +1219,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat |
|
|
|
|
|
|
|
|
|
|
|
if (holder != null) { |
|
|
|
if (holder != null) { |
|
|
|
activeCount++; |
|
|
|
activeCount++; |
|
|
|
|
|
|
|
logActiveCount(true); |
|
|
|
if (activeCount > activePeak) { |
|
|
|
if (activeCount > activePeak) { |
|
|
|
activePeak = activeCount; |
|
|
|
activePeak = activeCount; |
|
|
|
activePeakTime = System.currentTimeMillis(); |
|
|
|
activePeakTime = System.currentTimeMillis(); |
|
|
@ -1406,6 +1409,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat |
|
|
|
lock.lock(); |
|
|
|
lock.lock(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
activeCount--; |
|
|
|
activeCount--; |
|
|
|
|
|
|
|
logActiveCount(false); |
|
|
|
closeCount++; |
|
|
|
closeCount++; |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
lock.unlock(); |
|
|
|
lock.unlock(); |
|
|
@ -1424,6 +1428,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat |
|
|
|
lock.lockInterruptibly(); |
|
|
|
lock.lockInterruptibly(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
activeCount--; |
|
|
|
activeCount--; |
|
|
|
|
|
|
|
logActiveCount(false); |
|
|
|
closeCount++; |
|
|
|
closeCount++; |
|
|
|
|
|
|
|
|
|
|
|
result = putLast(holder, lastActiveTimeMillis); |
|
|
|
result = putLast(holder, lastActiveTimeMillis); |
|
|
@ -3124,4 +3129,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat |
|
|
|
public boolean isClosed() { |
|
|
|
public boolean isClosed() { |
|
|
|
return this.closed; |
|
|
|
return this.closed; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void logActiveCount(boolean isIncrease){ |
|
|
|
|
|
|
|
if (logActiveCount){ |
|
|
|
|
|
|
|
LOG.debug("activeCount " + (isIncrease ? "increase" : "decrease") + "current count is : " + activeCount, new Throwable()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|