Author: psteitz Date: Sat Feb 14 01:58:36 2015 New Revision: 1659744 URL: http://svn.apache.org/r1659744 Log: Eliminated synchronization in BasicDataSource getNumActive, getNumIdle methods.
Modified: commons/proper/dbcp/trunk/src/changes/changes.xml commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java Modified: commons/proper/dbcp/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/changes/changes.xml?rev=1659744&r1=1659743&r2=1659744&view=diff ============================================================================== --- commons/proper/dbcp/trunk/src/changes/changes.xml (original) +++ commons/proper/dbcp/trunk/src/changes/changes.xml Sat Feb 14 01:58:36 2015 @@ -115,6 +115,9 @@ The <action> type attribute can be add,u Added check to make sure that the PoolingConnectionFactory associated with a PoolingDataSource is correctly linked with its owning pool. </action> + <action dev="psteitz" type="update"> + Eliminated synchronization in BasicDataSource getNumActive, getNumIdle methods. + </action> </release> <release version="2.0.1" date="24 May 2014" description="This is a bug fix release."> <action dev="markt" type="fix"> Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java?rev=1659744&r1=1659743&r2=1659744&view=diff ============================================================================== --- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java (original) +++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java Sat Feb 14 01:58:36 2015 @@ -976,9 +976,11 @@ public class BasicDataSource implements * @return the current number of active connections */ @Override - public synchronized int getNumActive() { - if (connectionPool != null) { - return connectionPool.getNumActive(); + public int getNumActive() { + // Copy reference to avoid NPE if close happens after null check + GenericObjectPool<PoolableConnection> pool = connectionPool; + if (pool != null) { + return pool.getNumActive(); } return 0; } @@ -991,9 +993,11 @@ public class BasicDataSource implements * @return the current number of idle connections */ @Override - public synchronized int getNumIdle() { - if (connectionPool != null) { - return connectionPool.getNumIdle(); + public int getNumIdle() { + // Copy reference to avoid NPE if close happens after null check + GenericObjectPool<PoolableConnection> pool = connectionPool; + if (pool != null) { + return pool.getNumIdle(); } return 0; }