mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
1.系统计时器的时间(connectedTimeNano)记录到日志中不能准确的反映连接的时间(connectedTimeNano),换用(增加参数) connectedTimeMillis 记录获取连接的时间
2.处理 mysql 8 小时超时问题(即使testWhileIdle=false,testOnBorrow=false,testOnReturn=false),在物理连接的已连接时间超过 phyTimeoutMillis(默认7小时) 后就自动关闭该物理连接 3.修正单词拼写 destoryTask -> destroyTask
This commit is contained in:
@@ -138,7 +138,7 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
|
||||
// threads
|
||||
private ScheduledFuture<?> destroySchedulerFuture;
|
||||
private DestroyTask destoryTask;
|
||||
private DestroyTask destroyTask;
|
||||
|
||||
private CreateConnectionThread createConnectionThread;
|
||||
private DestroyConnectionThread destroyConnectionThread;
|
||||
@@ -684,14 +684,14 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
}
|
||||
|
||||
protected void createAndStartDestroyThread() {
|
||||
destoryTask = new DestroyTask();
|
||||
destroyTask = new DestroyTask();
|
||||
|
||||
if (destroyScheduler != null) {
|
||||
long period = timeBetweenEvictionRunsMillis;
|
||||
if (period <= 0) {
|
||||
period = 1000;
|
||||
}
|
||||
destroySchedulerFuture = destroyScheduler.scheduleAtFixedRate(destoryTask, period, period,
|
||||
destroySchedulerFuture = destroyScheduler.scheduleAtFixedRate(destroyTask, period, period,
|
||||
TimeUnit.MILLISECONDS);
|
||||
initedLatch.countDown();
|
||||
return;
|
||||
@@ -1941,7 +1941,7 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
break;
|
||||
}
|
||||
|
||||
destoryTask.run();
|
||||
destroyTask.run();
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
@@ -2031,8 +2031,8 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("abandon connection, owner thread: ");
|
||||
buf.append(pooledConnection.getOwnerThread().getName());
|
||||
buf.append(", connected time nano: ");
|
||||
buf.append(pooledConnection.getConnectedTimeNano());
|
||||
buf.append(", connected at : ");
|
||||
buf.append(pooledConnection.getConnectedTimeMillis());
|
||||
buf.append(", open stackTrace\n");
|
||||
|
||||
StackTraceElement[] trace = pooledConnection.getConnectStackTrace();
|
||||
@@ -2042,6 +2042,14 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
buf.append("\n");
|
||||
}
|
||||
|
||||
buf.append("ownerThread current state is "+pooledConnection.getOwnerThread().getState() + ", current stackTrace\n");
|
||||
trace = pooledConnection.getOwnerThread().getStackTrace();
|
||||
for (int i = 0; i < trace.length; i++) {
|
||||
buf.append("\tat ");
|
||||
buf.append(trace[i].toString());
|
||||
buf.append("\n");
|
||||
}
|
||||
|
||||
LOG.error(buf.toString());
|
||||
}
|
||||
}
|
||||
@@ -2118,6 +2126,12 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
for (int i = 0; i < checkCount; ++i) {
|
||||
DruidConnectionHolder connection = connections[i];
|
||||
|
||||
long phyConnectTimeMillis = connection.getTimeMillis();//physical connection connected time
|
||||
if( phyConnectTimeMillis > phyTimeoutMillis ){
|
||||
evictList.add(connection);//if physical connection connected greater than phyTimeoutMillis, close the connection, for mysql 8 hours timeout
|
||||
continue;
|
||||
}
|
||||
|
||||
if (checkTime) {
|
||||
long idleMillis = currentTimeMillis - connection.getLastActiveTimeMillis();
|
||||
if (idleMillis >= minEvictableIdleTimeMillis) {
|
||||
|
||||
Reference in New Issue
Block a user