mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge pull request #1072 from wenshao/master
bug fixed for DruidDataSource fail-fast
This commit is contained in:
@@ -1475,7 +1475,9 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
if (ex == null) {
|
||||
lock.lock();
|
||||
try {
|
||||
createError = null;
|
||||
if (createError != null) {
|
||||
createError = null;
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
@@ -1460,11 +1460,12 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
|
||||
try {
|
||||
while (poolingCount == 0) {
|
||||
emptySignal(); // send signal to CreateThread create connection
|
||||
|
||||
if (failFast && createError != null) {
|
||||
throw new DataSourceNotAvailableException(createError);
|
||||
}
|
||||
|
||||
emptySignal(); // send signal to CreateThread create connection
|
||||
notEmptyWaitThreadCount++;
|
||||
if (notEmptyWaitThreadCount > notEmptyWaitThreadPeak) {
|
||||
notEmptyWaitThreadPeak = notEmptyWaitThreadCount;
|
||||
@@ -1498,12 +1499,12 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
long estimate = nanos;
|
||||
|
||||
for (;;) {
|
||||
if (failFast && createError != null) {
|
||||
throw new DataSourceNotAvailableException(createError);
|
||||
}
|
||||
|
||||
if (poolingCount == 0) {
|
||||
emptySignal(); // send signal to CreateThread create connection
|
||||
|
||||
if (failFast && createError != null) {
|
||||
throw new DataSourceNotAvailableException(createError);
|
||||
}
|
||||
|
||||
if (estimate <= 0) {
|
||||
waitNanosLocal.set(nanos - estimate);
|
||||
@@ -1897,15 +1898,23 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
}
|
||||
|
||||
try {
|
||||
// 必须存在线程等待,才创建连接
|
||||
if (poolingCount >= notEmptyWaitThreadCount) {
|
||||
empty.await();
|
||||
boolean emptyWait = true;
|
||||
|
||||
if (createError != null && poolingCount == 0) {
|
||||
emptyWait = false;
|
||||
}
|
||||
|
||||
// 防止创建超过maxActive数量的连接
|
||||
if (activeCount + poolingCount >= maxActive) {
|
||||
empty.await();
|
||||
continue;
|
||||
|
||||
if (emptyWait) {
|
||||
// 必须存在线程等待,才创建连接
|
||||
if (poolingCount >= notEmptyWaitThreadCount) {
|
||||
empty.await();
|
||||
}
|
||||
|
||||
// 防止创建超过maxActive数量的连接
|
||||
if (activeCount + poolingCount >= maxActive) {
|
||||
empty.await();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
Reference in New Issue
Block a user