mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
JMX增强
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@705 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -818,41 +818,51 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
shrink(true);
|
||||
|
||||
if (isRemoveAbandoned()) {
|
||||
Iterator<Map.Entry<PoolableConnection, ActiveConnectionTraceInfo>> iter = activeConnections.entrySet().iterator();
|
||||
|
||||
long currentMillis = System.currentTimeMillis();
|
||||
|
||||
for (; iter.hasNext();) {
|
||||
Map.Entry<PoolableConnection, ActiveConnectionTraceInfo> entry = iter.next();
|
||||
ActiveConnectionTraceInfo activeInfo = entry.getValue();
|
||||
long timeMillis = activeInfo.getConnectTime() - currentMillis;
|
||||
|
||||
if (timeMillis >= removeAbandonedTimeoutMillis) {
|
||||
PoolableConnection pooledConnection = entry.getKey();
|
||||
JdbcUtils.close(pooledConnection);
|
||||
removeAbandonedCount++;
|
||||
|
||||
if (isLogAbandoned()) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("abandon connection, open stackTrace\n");
|
||||
|
||||
StackTraceElement[] trace = activeInfo.getStackTrace();
|
||||
for (int i = 0; i < trace.length; i++) {
|
||||
buf.append("\tat ");
|
||||
buf.append(trace[i].toString());
|
||||
buf.append("\n");
|
||||
}
|
||||
|
||||
LOG.error(buf.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
removeAbandoned();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int removeAbandoned() {
|
||||
int removeCount = 0;
|
||||
|
||||
Iterator<Map.Entry<PoolableConnection, ActiveConnectionTraceInfo>> iter = activeConnections.entrySet().iterator();
|
||||
|
||||
long currentMillis = System.currentTimeMillis();
|
||||
|
||||
for (; iter.hasNext();) {
|
||||
Map.Entry<PoolableConnection, ActiveConnectionTraceInfo> entry = iter.next();
|
||||
ActiveConnectionTraceInfo activeInfo = entry.getValue();
|
||||
long timeMillis = activeInfo.getConnectTime() - currentMillis;
|
||||
|
||||
if (timeMillis >= removeAbandonedTimeoutMillis) {
|
||||
PoolableConnection pooledConnection = entry.getKey();
|
||||
JdbcUtils.close(pooledConnection);
|
||||
removeAbandonedCount++;
|
||||
removeCount++;
|
||||
|
||||
if (isLogAbandoned()) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("abandon connection, open stackTrace\n");
|
||||
|
||||
StackTraceElement[] trace = activeInfo.getStackTrace();
|
||||
for (int i = 0; i < trace.length; i++) {
|
||||
buf.append("\tat ");
|
||||
buf.append(trace[i].toString());
|
||||
buf.append("\n");
|
||||
}
|
||||
|
||||
LOG.error(buf.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return removeCount;
|
||||
}
|
||||
|
||||
public DataSourceProxyConfig getConfig() {
|
||||
|
||||
Reference in New Issue
Block a user