mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
DruidDataSource add property phyMaxUseCount & shrinkQuietly.
This commit is contained in:
@@ -145,6 +145,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
protected volatile long minEvictableIdleTimeMillis = DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
|
||||
protected volatile long maxEvictableIdleTimeMillis = DEFAULT_MAX_EVICTABLE_IDLE_TIME_MILLIS;
|
||||
protected volatile long phyTimeoutMillis = DEFAULT_PHY_TIMEOUT_MILLIS;
|
||||
protected volatile long phyMaxUseCount = -1;
|
||||
|
||||
protected volatile boolean removeAbandoned;
|
||||
protected volatile long removeAbandonedTimeoutMillis = 300 * 1000;
|
||||
@@ -779,6 +780,14 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
this.phyTimeoutMillis = phyTimeoutMillis;
|
||||
}
|
||||
|
||||
public long getPhyMaxUseCount() {
|
||||
return phyMaxUseCount;
|
||||
}
|
||||
|
||||
public void setPhyMaxUseCount(long phyMaxUseCount) {
|
||||
this.phyMaxUseCount = phyMaxUseCount;
|
||||
}
|
||||
|
||||
public int getNumTestsPerEvictionRun() {
|
||||
return numTestsPerEvictionRun;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public final class DruidConnectionHolder {
|
||||
protected final long connectTimeMillis;
|
||||
protected volatile long lastActiveTimeMillis;
|
||||
protected volatile long lastValidTimeMillis;
|
||||
private long useCount = 0;
|
||||
protected long useCount = 0;
|
||||
private long keepAliveCheckCount = 0;
|
||||
private long lastNotEmptyWaitNanos;
|
||||
private final long createNanoSpan;
|
||||
|
||||
@@ -1671,6 +1671,11 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
return;
|
||||
}
|
||||
|
||||
if (phyMaxUseCount > 0 && holder.useCount >= phyMaxUseCount) {
|
||||
discardConnection(holder.conn);
|
||||
return;
|
||||
}
|
||||
|
||||
if (physicalConnection.isClosed()) {
|
||||
lock.lock();
|
||||
try {
|
||||
@@ -2833,7 +2838,11 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
holer.lastActiveTimeMillis = System.currentTimeMillis();
|
||||
put(holer);
|
||||
} else {
|
||||
JdbcUtils.close(connection);
|
||||
try {
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
}
|
||||
Arrays.fill(keepAliveConnections, null);
|
||||
|
||||
Reference in New Issue
Block a user