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:
@@ -143,7 +143,7 @@ public abstract class DruidAbstractDataSource implements DruidAbstractDataSource
|
||||
|
||||
protected boolean removeAbandoned;
|
||||
|
||||
protected int removeAbandonedTimeoutMillis;
|
||||
protected long removeAbandonedTimeoutMillis;
|
||||
|
||||
protected boolean logAbandoned;
|
||||
|
||||
@@ -283,18 +283,18 @@ public abstract class DruidAbstractDataSource implements DruidAbstractDataSource
|
||||
}
|
||||
|
||||
public int getRemoveAbandonedTimeout() {
|
||||
return removeAbandonedTimeoutMillis / 1000;
|
||||
return (int) (removeAbandonedTimeoutMillis / 1000);
|
||||
}
|
||||
|
||||
public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) {
|
||||
this.removeAbandonedTimeoutMillis = removeAbandonedTimeout * 1000;
|
||||
}
|
||||
|
||||
public void setRemoveAbandonedTimeoutMillis(int removeAbandonedTimeoutMillis) {
|
||||
public void setRemoveAbandonedTimeoutMillis(long removeAbandonedTimeoutMillis) {
|
||||
this.removeAbandonedTimeoutMillis = removeAbandonedTimeoutMillis;
|
||||
}
|
||||
|
||||
public int getRemoveAbandonedTimeoutMillis() {
|
||||
public long getRemoveAbandonedTimeoutMillis() {
|
||||
return removeAbandonedTimeoutMillis;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public interface DruidAbstractDataSourceMBean {
|
||||
|
||||
boolean isRemoveAbandoned();
|
||||
|
||||
int getRemoveAbandonedTimeoutMillis();
|
||||
long getRemoveAbandonedTimeoutMillis();
|
||||
|
||||
List<String> getActiveConnectionStackTrace();
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -24,6 +24,8 @@ public interface DruidDataSourceMBean extends DruidAbstractDataSourceMBean {
|
||||
|
||||
void shrink();
|
||||
|
||||
int removeAbandoned();
|
||||
|
||||
String toString();
|
||||
|
||||
int getWaitThreadCount();
|
||||
@@ -31,7 +33,7 @@ public interface DruidDataSourceMBean extends DruidAbstractDataSourceMBean {
|
||||
int getLockQueueLength();
|
||||
|
||||
long getNotEmptyWaitCount();
|
||||
|
||||
|
||||
long getNotEmptySignalCount();
|
||||
|
||||
long getNotEmptyWaitMillis();
|
||||
@@ -39,10 +41,10 @@ public interface DruidDataSourceMBean extends DruidAbstractDataSourceMBean {
|
||||
long getNotEmptyWaitNanos();
|
||||
|
||||
void resetStat();
|
||||
|
||||
|
||||
boolean isResetStatEnable();
|
||||
|
||||
|
||||
void setResetStatEnable(boolean resetStatEnable);
|
||||
|
||||
|
||||
String getVersion();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user