mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add api:tryGetConnection and fillConnection
This commit is contained in:
@@ -2406,4 +2406,46 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
public void setLogDiffrentThread(boolean logDiffrentThread) {
|
||||
this.logDiffrentThread = logDiffrentThread;
|
||||
}
|
||||
|
||||
public DruidPooledConnection tryGetConnection() throws SQLException {
|
||||
if (poolingCount == 0) {
|
||||
return null;
|
||||
}
|
||||
return getConnection();
|
||||
}
|
||||
|
||||
public void fillConnection() throws SQLException {
|
||||
if (closed) {
|
||||
throw new DataSourceClosedException("dataSource already closed at " + new Date(closeTimeMillis));
|
||||
}
|
||||
|
||||
if (!enable) {
|
||||
throw new DataSourceDisableException();
|
||||
}
|
||||
|
||||
if (this.poolingCount + this.activeCount >= this.maxActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
int fillConnetionCount = 0;
|
||||
try {
|
||||
for (; this.poolingCount + this.activeCount < this.maxActive; fillConnetionCount++) {
|
||||
Connection conn = createPhysicalConnection();
|
||||
DruidConnectionHolder holder = new DruidConnectionHolder(this, conn);
|
||||
connections[poolingCount++] = holder;
|
||||
if (poolingCount > poolingPeak) {
|
||||
poolingPeak = poolingCount;
|
||||
poolingPeakTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
LOG.error("fill connection error", ex);
|
||||
}
|
||||
|
||||
if (LOG.isInfoEnabled()) {
|
||||
LOG.info("fill " + fillConnetionCount + " connections");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user