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@627 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -257,16 +257,14 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
|
||||
Connection realConnection = poolalbeConnection.getConnection();
|
||||
JdbcUtils.close(realConnection);
|
||||
this.decrementActiveCountWithLock();
|
||||
discardConnection(realConnection);
|
||||
continue;
|
||||
}
|
||||
poolalbeConnection.getConnectionHolder().setLastCheckTimeMillis(System.currentTimeMillis());
|
||||
} else {
|
||||
Connection realConnection = poolalbeConnection.getConnection();
|
||||
if (realConnection.isClosed()) {
|
||||
JdbcUtils.close(realConnection);
|
||||
this.decrementActiveCountWithLock();
|
||||
discardConnection(realConnection);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -280,8 +278,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
LOG.debug("skip not validate connection.");
|
||||
}
|
||||
|
||||
JdbcUtils.close(realConnection);
|
||||
this.decrementActiveCountWithLock();
|
||||
discardConnection(realConnection);
|
||||
continue;
|
||||
}
|
||||
poolalbeConnection.getConnectionHolder().setLastCheckTimeMillis(System.currentTimeMillis());
|
||||
@@ -300,6 +297,22 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
}
|
||||
|
||||
private void discardConnection(Connection realConnection) throws SQLException {
|
||||
JdbcUtils.close(realConnection);
|
||||
|
||||
try {
|
||||
lock.lockInterruptibly();
|
||||
} catch (InterruptedException e) {
|
||||
throw new SQLException("interrupt", e);
|
||||
}
|
||||
|
||||
try {
|
||||
activeCount--;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private PoolableConnection getConnectionInternal() throws SQLException {
|
||||
PoolableConnection poolalbeConnection;
|
||||
|
||||
@@ -361,8 +374,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
// exceptionSorter.isExceptionFatal
|
||||
if (exceptionSoter != null && exceptionSoter.isExceptionFatal(sqlEx)) {
|
||||
decrementActiveCountWithLock();
|
||||
JdbcUtils.close(holder.getConnection());
|
||||
this.discardConnection(holder.getConnection());
|
||||
pooledConnection.disable();
|
||||
}
|
||||
|
||||
@@ -490,20 +502,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
createConnectionCount++;
|
||||
}
|
||||
|
||||
void decrementActiveCountWithLock() throws SQLException {
|
||||
try {
|
||||
lock.lockInterruptibly();
|
||||
} catch (InterruptedException e) {
|
||||
throw new SQLException("interrupt", e);
|
||||
}
|
||||
|
||||
try {
|
||||
activeCount--;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void putLast(ConnectionHolder e) {
|
||||
if (e == null) {
|
||||
throw new NullPointerException();
|
||||
|
||||
Reference in New Issue
Block a user