mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add dynamic change maxActive support
This commit is contained in:
@@ -76,54 +76,54 @@ import com.alibaba.druid.util.JdbcUtils;
|
||||
*/
|
||||
public class DruidDataSource extends DruidAbstractDataSource implements DruidDataSourceMBean, ManagedDataSource, Referenceable, Closeable, Cloneable, ConnectionPoolDataSource {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(DruidDataSource.class);
|
||||
private final static Log LOG = LogFactory.getLog(DruidDataSource.class);
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Condition notEmpty = lock.newCondition();
|
||||
private final Condition empty = lock.newCondition();
|
||||
private final Condition notEmpty = lock.newCondition();
|
||||
private final Condition empty = lock.newCondition();
|
||||
|
||||
// stats
|
||||
private long connectCount = 0L;
|
||||
private long closeCount = 0L;
|
||||
private final AtomicLong connectErrorCount = new AtomicLong();
|
||||
private long recycleCount = 0L;
|
||||
private long createConnectionCount = 0L;
|
||||
private long destroyCount = 0L;
|
||||
private long removeAbandonedCount = 0L;
|
||||
private long notEmptyWaitCount = 0L;
|
||||
private long notEmptySignalCount = 0L;
|
||||
private long notEmptyWaitNanos = 0L;
|
||||
private long connectCount = 0L;
|
||||
private long closeCount = 0L;
|
||||
private final AtomicLong connectErrorCount = new AtomicLong();
|
||||
private long recycleCount = 0L;
|
||||
private long createConnectionCount = 0L;
|
||||
private long destroyCount = 0L;
|
||||
private long removeAbandonedCount = 0L;
|
||||
private long notEmptyWaitCount = 0L;
|
||||
private long notEmptySignalCount = 0L;
|
||||
private long notEmptyWaitNanos = 0L;
|
||||
|
||||
private int activePeak = 0;
|
||||
private long activePeakTime = 0;
|
||||
private int poolingPeak = 0;
|
||||
private long poolingPeakTime = 0;
|
||||
private int activePeak = 0;
|
||||
private long activePeakTime = 0;
|
||||
private int poolingPeak = 0;
|
||||
private long poolingPeakTime = 0;
|
||||
|
||||
// store
|
||||
private ConnectionHolder[] connections;
|
||||
private int poolingCount = 0;
|
||||
private int activeCount = 0;
|
||||
private long discardCount = 0;
|
||||
private int notEmptyWaitThreadCount = 0;
|
||||
private int notEmptyWaitThreadPeak = 0;
|
||||
private volatile ConnectionHolder[] connections;
|
||||
private int poolingCount = 0;
|
||||
private int activeCount = 0;
|
||||
private long discardCount = 0;
|
||||
private int notEmptyWaitThreadCount = 0;
|
||||
private int notEmptyWaitThreadPeak = 0;
|
||||
|
||||
// threads
|
||||
private CreateConnectionThread createConnectionThread;
|
||||
private DestroyConnectionThread destoryConnectionThread;
|
||||
private CreateConnectionThread createConnectionThread;
|
||||
private DestroyConnectionThread destoryConnectionThread;
|
||||
|
||||
private final CountDownLatch initedLatch = new CountDownLatch(2);
|
||||
private final CountDownLatch initedLatch = new CountDownLatch(2);
|
||||
|
||||
private boolean enable = true;
|
||||
private boolean enable = true;
|
||||
|
||||
private boolean resetStatEnable = true;
|
||||
private boolean resetStatEnable = true;
|
||||
|
||||
private String initStackTrace;
|
||||
private String initStackTrace;
|
||||
|
||||
private boolean closed = false;
|
||||
private long closeTimeMillis = -1L;
|
||||
private boolean closed = false;
|
||||
private long closeTimeMillis = -1L;
|
||||
|
||||
private JdbcDataSourceStat dataSourceStat;
|
||||
private JdbcDataSourceStat dataSourceStat;
|
||||
|
||||
public DruidDataSource(){
|
||||
}
|
||||
@@ -216,6 +216,19 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
|
||||
public void setPoolPreparedStatements(boolean value) {
|
||||
if (this.poolPreparedStatements == value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!inited) {
|
||||
this.poolPreparedStatements = value;
|
||||
return;
|
||||
}
|
||||
|
||||
if (LOG.isInfoEnabled()) {
|
||||
LOG.info("set poolPreparedStatements " + this.poolPreparedStatements + " -> " + value);
|
||||
}
|
||||
|
||||
lock.lock();
|
||||
try {
|
||||
if (this.poolPreparedStatements && (!value)) {
|
||||
@@ -230,7 +243,36 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
connection.getStatementPool().getMap().clear();
|
||||
}
|
||||
}
|
||||
super.setPoolPreparedStatements(value);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void setMaxActive(int maxActive) {
|
||||
if (this.maxActive == maxActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!inited) {
|
||||
this.maxActive = maxActive;
|
||||
return;
|
||||
}
|
||||
|
||||
if (LOG.isInfoEnabled()) {
|
||||
LOG.info("set maxActive " + this.maxActive + " -> " + maxActive);
|
||||
}
|
||||
|
||||
lock.lock();
|
||||
try {
|
||||
int allCount = this.poolingCount + this.activeCount;
|
||||
|
||||
if (maxActive > allCount) {
|
||||
this.connections = Arrays.copyOf(this.connections, maxActive);
|
||||
} else {
|
||||
this.connections = Arrays.copyOf(this.connections, allCount);
|
||||
}
|
||||
|
||||
this.maxActive = maxActive;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user