在DruidDataSource.init.initCheck 中有一句日志,不要用在线上
如何进行连接池泄露的检测
连接池泄露指的是连接资源没有close掉,没有归还到连接池如果开启removeAbandoned,销毁独立线程会执行removeAbandoned检测一下,拿到已获取连接时间长度,如果大于阈值,且没有执行statement,将这个connection执行close方法,进行回收
为什么默认是关闭的?线上也不允许使用?
生产环境中连接的关闭应该靠程序自己保证,否则可能会隐藏问题
com.alibaba.druid.pool.DruidDataSource#getConnectionDirect
if (removeAbandoned) {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
poolableConnection.connectStackTrace = stackTrace;
poolableConnection.setConnectedTimeNano();
poolableConnection.traceEnable = true;
activeConnectionLock.lock();
try {
// 只有removeAbandoned开启时,才会想activeConnections里面存连接对象
activeConnections.put(poolableConnection, PRESENT);
} finally {
activeConnectionLock