Skip to content

Commit

Permalink
0001910: Too many connections when network environment is bad. Bug in…
Browse files Browse the repository at this point in the history
… DBCP.
  • Loading branch information
chenson42 committed Aug 14, 2014
1 parent 2fc22c2 commit 3144199
Showing 1 changed file with 34 additions and 0 deletions.
Expand Up @@ -22,13 +22,19 @@

import java.sql.SQLException;

import org.apache.commons.dbcp.AbandonedConfig;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.dbcp.ConnectionFactory;
import org.apache.commons.dbcp.PoolableConnectionFactory;
import org.apache.commons.dbcp.SQLNestedException;
import org.apache.commons.pool.KeyedObjectPoolFactory;

/**
* A subclass of {@link BasicDataSource} which allows for a data source to be
* closed (all underlying connections are closed) and then allows new
* connections to be created.
*/
@SuppressWarnings("deprecation")
public class ResettableBasicDataSource extends BasicDataSource {

public ResettableBasicDataSource() {
Expand All @@ -47,5 +53,33 @@ public synchronized void close() {
}

}

@Override
protected void createPoolableConnectionFactory(ConnectionFactory driverConnectionFactory,
KeyedObjectPoolFactory statementPoolFactory, AbandonedConfig configuration) throws SQLException {
PoolableConnectionFactory connectionFactory = null;
try {
connectionFactory =
new PoolableConnectionFactory(driverConnectionFactory,
connectionPool,
statementPoolFactory,
validationQuery,
validationQueryTimeout,
connectionInitSqls,
defaultReadOnly,
defaultAutoCommit,
defaultTransactionIsolation,
defaultCatalog,
configuration);
validateConnectionFactory(connectionFactory);
} catch (Exception e) {
try {
connectionPool.close();
} catch (Exception e1) {
}
throw new SQLNestedException("Cannot create PoolableConnectionFactory (" + e.getMessage() + ")", e);
}
}


}

0 comments on commit 3144199

Please sign in to comment.