mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@513 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -91,8 +91,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
private CreateConnectionThread createConnectionThread;
|
||||
private DestroyConnectionThread destoryConnectionThread;
|
||||
|
||||
private boolean removeAbandoned = false;
|
||||
|
||||
private final IdentityHashMap<PoolableConnection, ActiveConnectionTraceInfo> activeConnections = new IdentityHashMap<PoolableConnection, ActiveConnectionTraceInfo>();
|
||||
|
||||
private final CountDownLatch initedLatch = new CountDownLatch(2);
|
||||
@@ -269,8 +267,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
LOG.debug("skip not validate connection.");
|
||||
}
|
||||
|
||||
Connection realConnection = poolalbeConnection.getConnection();
|
||||
JdbcUtils.close(realConnection);
|
||||
poolalbeConnection.close(false);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
@@ -281,11 +278,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
}
|
||||
|
||||
if (removeAbandoned) {
|
||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
activeConnections.put(poolalbeConnection, new ActiveConnectionTraceInfo(poolalbeConnection, System.currentTimeMillis(), stackTrace));
|
||||
}
|
||||
|
||||
return poolalbeConnection;
|
||||
}
|
||||
}
|
||||
@@ -325,6 +317,11 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
activeCount++;
|
||||
|
||||
poolalbeConnection = new PoolableConnection(holder);
|
||||
|
||||
if (removeAbandoned) {
|
||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
activeConnections.put(poolalbeConnection, new ActiveConnectionTraceInfo(poolalbeConnection, System.currentTimeMillis(), stackTrace));
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
connectErrorCount++;
|
||||
throw new SQLException(e.getMessage(), e);
|
||||
@@ -347,10 +344,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
assert holder != null;
|
||||
|
||||
try {
|
||||
if (removeAbandoned) {
|
||||
activeConnections.remove(pooledConnection);
|
||||
}
|
||||
|
||||
// 第一步,检查连接是否关闭
|
||||
if (conn == null || conn.isClosed()) {
|
||||
lock.lock();
|
||||
|
||||
@@ -43,6 +43,7 @@ import com.alibaba.druid.logging.Log;
|
||||
import com.alibaba.druid.logging.LogFactory;
|
||||
import com.alibaba.druid.pool.PoolablePreparedStatement.PreparedStatementKey;
|
||||
import com.alibaba.druid.pool.PreparedStatementPool.MethodType;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
/**
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
@@ -123,11 +124,20 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
close(true);
|
||||
}
|
||||
|
||||
public void close(boolean recyle) throws SQLException {
|
||||
if (holder == null) {
|
||||
LOG.warn("dup close");
|
||||
return;
|
||||
}
|
||||
|
||||
DruidAbstractDataSource dataSource = holder.getDataSource();
|
||||
if (dataSource.isRemoveAbandoned()) {
|
||||
dataSource.getActiveConnectionStackTrace().remove(this);
|
||||
}
|
||||
|
||||
for (ConnectionEventListener listener : holder.getConnectionEventListeners()) {
|
||||
listener.connectionClosed(new ConnectionEvent(this));
|
||||
}
|
||||
@@ -142,7 +152,11 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
}
|
||||
|
||||
holder.reset();
|
||||
holder.getDataSource().recycle(this);
|
||||
if (recyle) {
|
||||
holder.getDataSource().recycle(this);
|
||||
} else {
|
||||
JdbcUtils.close(holder.getConnection());
|
||||
}
|
||||
holder = null;
|
||||
conn = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user