JMX增强

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@705 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-09-09 16:40:29 +00:00
parent 8b36173bd0
commit 16c6a42d1b
6 changed files with 67 additions and 46 deletions
@@ -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() {