async close support

This commit is contained in:
wenshao
2014-08-29 06:14:26 +08:00
parent 6caf8fe300
commit 8551bf6580
5 changed files with 293 additions and 3 deletions
@@ -1169,6 +1169,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
if (requireDiscard) {
this.discardConnection(holder.getConnection());
holder.setDiscard(true);
}
LOG.error("discard connection", sqlEx);
@@ -1225,7 +1226,18 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
// reset holder, restore default settings, clear warnings
holder.reset();
boolean isSameThread = pooledConnection.getOwnerThread() == Thread.currentThread();
if (!isSameThread) {
synchronized (pooledConnection) {
holder.reset();
}
} else {
holder.reset();
}
if (holder.isDiscard()) {
return;
}
if (testOnReturn) {
boolean validate = testConnectionInternal(physicalConnection);
@@ -217,7 +217,14 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
return;
}
if (holder.getDataSource().isAsyncCloseConnectionEnable()) {
DruidAbstractDataSource dataSource = holder.getDataSource();
boolean isSameThread = this.getOwnerThread() == Thread.currentThread();
if (!isSameThread) {
dataSource.setAsyncCloseConnectionEnable(true);
}
if (dataSource.isAsyncCloseConnectionEnable()) {
syncClose();
return;
}
@@ -226,7 +233,7 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
listener.connectionClosed(new ConnectionEvent(this));
}
DruidAbstractDataSource dataSource = holder.getDataSource();
List<Filter> filters = dataSource.getProxyFilters();
if (filters.size() > 0) {
FilterChainImpl filterChain = new FilterChainImpl(dataSource);