HHH-7699 DriverManagerConnectionProviderImpl is not exact in counting checked-out connections

This commit is contained in:
Sanne Grinovero 2012-10-17 15:27:44 +01:00
parent e4300d279c
commit 4fe494d13d
1 changed files with 6 additions and 5 deletions

View File

@ -29,6 +29,7 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -68,7 +69,7 @@ public class DriverManagerConnectionProviderImpl
private boolean autocommit; private boolean autocommit;
private final ArrayList<Connection> pool = new ArrayList<Connection>(); private final ArrayList<Connection> pool = new ArrayList<Connection>();
private int checkedOut = 0; private final AtomicInteger checkedOut = new AtomicInteger();
private boolean stopped; private boolean stopped;
@ -170,7 +171,7 @@ public class DriverManagerConnectionProviderImpl
public Connection getConnection() throws SQLException { public Connection getConnection() throws SQLException {
final boolean traceEnabled = LOG.isTraceEnabled(); final boolean traceEnabled = LOG.isTraceEnabled();
if ( traceEnabled ) LOG.tracev( "Total checked-out connections: {0}", checkedOut ); if ( traceEnabled ) LOG.tracev( "Total checked-out connections: {0}", checkedOut.intValue() );
// essentially, if we have available connections in the pool, use one... // essentially, if we have available connections in the pool, use one...
synchronized (pool) { synchronized (pool) {
@ -184,7 +185,7 @@ public class DriverManagerConnectionProviderImpl
if ( pooled.getAutoCommit() != autocommit ) { if ( pooled.getAutoCommit() != autocommit ) {
pooled.setAutoCommit( autocommit ); pooled.setAutoCommit( autocommit );
} }
checkedOut++; checkedOut.incrementAndGet();
return pooled; return pooled;
} }
} }
@ -206,12 +207,12 @@ public class DriverManagerConnectionProviderImpl
LOG.debugf( "Created connection to: %s, Isolation Level: %s", url, conn.getTransactionIsolation() ); LOG.debugf( "Created connection to: %s, Isolation Level: %s", url, conn.getTransactionIsolation() );
} }
checkedOut++; checkedOut.incrementAndGet();
return conn; return conn;
} }
public void closeConnection(Connection conn) throws SQLException { public void closeConnection(Connection conn) throws SQLException {
checkedOut--; checkedOut.decrementAndGet();
final boolean traceEnabled = LOG.isTraceEnabled(); final boolean traceEnabled = LOG.isTraceEnabled();
// add to the pool if the max size is not yet reached. // add to the pool if the max size is not yet reached.