mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
修正connection.close的并发问题
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@326 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -271,6 +271,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
*/
|
||||
protected void recycle(PoolableConnection pooledConnection) throws SQLException {
|
||||
final Connection conn = pooledConnection.getConnection();
|
||||
ConnectionHolder holder = pooledConnection.getConnectionHolder();
|
||||
|
||||
assert holder != null;
|
||||
|
||||
try {
|
||||
if (activeConnectionTraceEnable) {
|
||||
activeConnections.remove(pooledConnection);
|
||||
@@ -280,6 +284,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
if (conn == null || conn.isClosed()) {
|
||||
lock.lock();
|
||||
try {
|
||||
holder.reset();
|
||||
decrementActiveCount();
|
||||
closeCount++;
|
||||
} finally {
|
||||
@@ -306,6 +311,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
if (count >= maxIdle) {
|
||||
lock.lock();
|
||||
try {
|
||||
holder.reset();
|
||||
conn.close();
|
||||
decrementActiveCount();
|
||||
} finally {
|
||||
@@ -328,7 +334,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
closeCount++;
|
||||
|
||||
// 第六步,加入队列中(putLast)
|
||||
putLast(pooledConnection.getConnectionHolder());
|
||||
holder.reset();
|
||||
putLast(holder);
|
||||
recycleCount++;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
|
||||
@@ -57,7 +57,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
protected SQLException handleException(Throwable t) throws SQLException {
|
||||
final ConnectionHolder holder = this.holder;
|
||||
|
||||
//
|
||||
//
|
||||
if (holder != null) {
|
||||
DruidAbstractDataSource dataSource = holder.getDataSource();
|
||||
if (dataSource != null) {
|
||||
@@ -124,7 +124,6 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
}
|
||||
|
||||
holder.getDataSource().recycle(this);
|
||||
holder.reset();
|
||||
holder = null;
|
||||
conn = null;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
|
||||
private final Statement stmt;
|
||||
protected PoolableConnection conn;
|
||||
protected final List<ResultSet> resultSetTrace = new ArrayList<ResultSet>();
|
||||
protected boolean closed = false;
|
||||
|
||||
public PoolableStatement(PoolableConnection conn, Statement stmt){
|
||||
this.conn = conn;
|
||||
@@ -49,6 +50,10 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
|
||||
this.conn = conn;
|
||||
}
|
||||
|
||||
public Statement getStatement() {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
protected void clearResultSet() {
|
||||
for (ResultSet rs : resultSetTrace) {
|
||||
try {
|
||||
@@ -90,6 +95,7 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
|
||||
clearResultSet();
|
||||
|
||||
stmt.close();
|
||||
this.closed = true;
|
||||
|
||||
conn.getConnectionHolder().removeTrace(this);
|
||||
}
|
||||
@@ -409,6 +415,10 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
|
||||
|
||||
@Override
|
||||
public final boolean isClosed() throws SQLException {
|
||||
if (this.closed) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
return stmt.isClosed();
|
||||
} catch (Throwable t) {
|
||||
|
||||
Reference in New Issue
Block a user