bug fixed : remove abondanded failed warnnings

This commit is contained in:
wenshao
2011-12-08 12:36:15 +08:00
parent a92d21cfab
commit 187f0ea5ed
6 changed files with 30 additions and 15 deletions
@@ -414,6 +414,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
activeConnections.put(poolalbeConnection,
new ActiveConnectionTraceInfo(poolalbeConnection, System.currentTimeMillis(),
stackTrace));
poolalbeConnection.setTraceEnable(true);
}
if (!this.isDefaultAutoCommit()) {
@@ -530,10 +531,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
assert holder != null;
if (isRemoveAbandoned()) {
if (pooledConnection.isTraceEnable()) {
ActiveConnectionTraceInfo oldInfo = activeConnections.remove(pooledConnection);
if (oldInfo == null) {
LOG.warn("remove abandonded failed.");
LOG.warn("remove abandonded failed. activeConnections.size " + activeConnections.size());
}
}
@@ -615,6 +616,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
public void close() {
lock.lock();
try {
if (!this.inited) {
return;
}
if (createConnectionThread != null) {
createConnectionThread.interrupt();
}
@@ -704,7 +709,9 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
notEmptyWaitThreadCount++;
try {
long startEstimate = estimate;
estimate = notEmpty.awaitNanos(estimate); // signal by recycle or creator
estimate = notEmpty.awaitNanos(estimate); // signal by
// recycle or
// creator
notEmptyWaitCount++;
notEmptyWaitNanos += (startEstimate - estimate);
@@ -51,12 +51,13 @@ import com.alibaba.druid.util.TransactionInfo;
*/
public class PoolableConnection implements PooledConnection, Connection {
private final static Log LOG = LogFactory.getLog(PoolableConnection.class);
private final static Log LOG = LogFactory.getLog(PoolableConnection.class);
protected Connection conn;
protected ConnectionHolder holder;
protected TransactionInfo transactionInfo;
private final boolean dupCloseLogEnable;
private boolean traceEnable = false;
public PoolableConnection(ConnectionHolder holder){
this.conn = holder.getConnection();
@@ -64,6 +65,14 @@ public class PoolableConnection implements PooledConnection, Connection {
dupCloseLogEnable = holder.getDataSource().isDupCloseLogEnable();
}
public boolean isTraceEnable() {
return traceEnable;
}
public void setTraceEnable(boolean traceEnable) {
this.traceEnable = traceEnable;
}
public SQLException handleException(Throwable t) throws SQLException {
final ConnectionHolder holder = this.holder;
@@ -84,7 +93,7 @@ public class PoolableConnection implements PooledConnection, Connection {
if (this.isClosed()) {
return;
}
PreparedStatement rawStatement = stmt.getRawPreparedStatement();
try {
@@ -92,7 +101,7 @@ public class PoolableConnection implements PooledConnection, Connection {
} catch (SQLException ex) {
LOG.error("clear parameter error", ex);
}
if (holder == null) {
return;
}
@@ -130,11 +139,6 @@ public class PoolableConnection implements PooledConnection, Connection {
return;
}
DruidAbstractDataSource dataSource = holder.getDataSource();
if (dataSource.isRemoveAbandoned()) {
dataSource.removeActiveConnection(this);
}
for (ConnectionEventListener listener : holder.getConnectionEventListeners()) {
listener.connectionClosed(new ConnectionEvent(this));
}
@@ -93,9 +93,13 @@ public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBe
public synchronized static void remove(DruidDataSource dataSource) {
ObjectName objectName = dataSources.remove(dataSource);
if (objectName == null) {
objectName = dataSource.getObjectName();
}
if (objectName == null) {
LOG.error("unregister mbean failed.");
LOG.error("unregister mbean failed. url " + dataSource.getUrl());
return;
}