public DruidPooledConnection
getConnectionDirect(long maxWaitMillis
) throws SQLException
{
int notFullTimeoutRetryCnt
= 0;
for (;;) {
DruidPooledConnection poolableConnection
;
try {
poolableConnection
= getConnectionInternal(maxWaitMillis
);
} catch (GetConnectionTimeoutException ex
) {
if (notFullTimeoutRetryCnt
<= this.notFullTimeoutRetryCount
&& !isFull()) {
notFullTimeoutRetryCnt
++;
if (LOG
.isWarnEnabled()) {
LOG
.warn("get connection timeout retry : " + notFullTimeoutRetryCnt
);
}
continue;
}
throw ex
;
}
if (testOnBorrow
) {
boolean validate
= testConnectionInternal(poolableConnection
.holder
, poolableConnection
.conn
);
if (!validate
) {
if (LOG
.isDebugEnabled()) {
LOG
.debug("skip not validate connection.");
}
Connection realConnection
= poolableConnection
.conn
;
discardConnection(realConnection
);
continue;
}
} else {
Connection realConnection
= poolableConnection
.conn
;
if (poolableConnection
.conn
.isClosed()) {
discardConnection(null
);
continue;
}
if (testWhileIdle
) {
final DruidConnectionHolder holder
= poolableConnection
.holder
;
long currentTimeMillis
= System
.currentTimeMillis();
long lastActiveTimeMillis
= holder
.lastActiveTimeMillis
;
long lastKeepTimeMillis
= holder
.lastKeepTimeMillis
;
if (lastKeepTimeMillis
> lastActiveTimeMillis
) {
lastActiveTimeMillis
= lastKeepTimeMillis
;
}
long idleMillis
= currentTimeMillis
- lastActiveTimeMillis
;
long timeBetweenEvictionRunsMillis
= this.timeBetweenEvictionRunsMillis
;
if (timeBetweenEvictionRunsMillis
<= 0) {
timeBetweenEvictionRunsMillis
= DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS
;
}
if (idleMillis
>= timeBetweenEvictionRunsMillis
|| idleMillis
< 0
) {
boolean validate
= testConnectionInternal(poolableConnection
.holder
, poolableConnection
.conn
);
if (!validate
) {
if (LOG
.isDebugEnabled()) {
LOG
.debug("skip not validate connection.");
}
discardConnection(realConnection
);
continue;
}
}
}
}
if (removeAbandoned
) {
StackTraceElement
[] stackTrace
= Thread
.currentThread().getStackTrace();
poolableConnection
.connectStackTrace
= stackTrace
;
poolableConnection
.setConnectedTimeNano();
poolableConnection
.traceEnable
= true;
activeConnectionLock
.lock();
try {
activeConnections
.put(poolableConnection
, PRESENT
);
} finally {
activeConnectionLock
.unlock();
}
}
if (!this.defaultAutoCommit
) {
poolableConnection
.setAutoCommit(false);
}
return poolableConnection
;
}
}