mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add notFullTimeoutRetryCount support
This commit is contained in:
@@ -238,6 +238,17 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
this.setResetStatEnable(value);
|
||||
}
|
||||
}
|
||||
{
|
||||
String property = properties.getProperty("druid.notFullTimeoutRetryCount");
|
||||
if (property != null && property.length() > 0) {
|
||||
try {
|
||||
int value = Integer.parseInt(property);
|
||||
this.setNotFullTimeoutRetryCount(value);
|
||||
} catch (NumberFormatException e) {
|
||||
LOG.error("illegal property 'druid.notFullTimeoutRetryCount'", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isUseGlobalDataSourceStat() {
|
||||
@@ -897,8 +908,22 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
|
||||
public DruidPooledConnection getConnectionDirect(long maxWaitMillis) throws SQLException {
|
||||
int notFullTimeoutRetryCnt = 0;
|
||||
for (;;) {
|
||||
DruidPooledConnection poolableConnection = getConnectionInternal(maxWaitMillis);
|
||||
// handle notFullTimeoutRetry
|
||||
DruidPooledConnection poolableConnection;
|
||||
try {
|
||||
poolableConnection = getConnectionInternal(maxWaitMillis);
|
||||
} catch (GetConnectionTimeoutException ex) {
|
||||
if (notFullTimeoutRetryCnt <= this.notFullTimeoutRetryCount && !isFull()) {
|
||||
notFullTimeoutRetryCnt++;
|
||||
if (LOG.isWarnEnabled()) {
|
||||
LOG.warn("not full timeout retry : " + notFullTimeoutRetryCnt);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
|
||||
if (isTestOnBorrow()) {
|
||||
boolean validate = testConnectionInternal(poolableConnection.getConnection());
|
||||
@@ -2497,4 +2522,13 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
lock.lock();
|
||||
try {
|
||||
return this.poolingCount + this.activeCount >= this.maxActive;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user