6
错误代码如下
protected final void handleFatalError(DruidPooledConnection conn,
SQLException error,
String sql) throws SQLException {
final DruidConnectionHolder holder = conn.holder;
if (conn.isTraceEnable()) {
activeConnectionLock.lock();
try {
if (conn.isTraceEnable()) {
activeConnections.remove(conn);
conn.setTraceEnable(false);
}
} finally {
activeConnectionLock.unlock();
}
}
long lastErrorTimeMillis = this.lastErrorTimeMillis;
if (lastErrorTimeMillis == 0) {
lastErrorTimeMillis = System.currentTimeMillis();
}
if (sql != null && sql.length() > 1024) {
sql = sql.substring(0, 1024);
}
boolean requireDiscard = false;
final ReentrantLock lock = conn.lock;
lock.lock();
try {
if ((!conn.isClosed()) && !conn.isDisable()) {
conn.disable(error);
requireDiscard = true;
}
lastFatalErrorTimeMillis = lastErrorTimeMillis;
fatalErrorCount++;
if (fatalErrorCount - fatalErrorCountLastShrink > onFatalErrorMaxActive) {
onFatalError = true;
}
lastFatalError = error;
lastFatalErrorSql = sql;
} finally {
lock.unlock();
}
if (onFatalError && holder != null && holder.getDataSource() != null) {
ReentrantLock dataSourceLock = holder.getDataSource().lock;
dataSourceLock.lock();
try {
emptySignal();
} finally {
dataSourceLock.unlock();
}
}
if (requireDiscard) {
if (holder.statementTrace != null) {
holder.lock.lock();
try {
for (Statement stmt : holder.statementTrace) {
JdbcUtils.close(stmt);
}
} finally {
holder.lock.unlock();
}
}
this.discardConnection(holder);
}
// holder.
LOG.error("{conn-" + holder.getConnectionId() + "} discard", error);
}