Skip to content

Commit

Permalink
HHH-7699 DriverManagerConnectionProviderImpl is not exact in counting…
Browse files Browse the repository at this point in the history
… checked-out connections
  • Loading branch information
Sanne committed Oct 18, 2012
1 parent e4300d2 commit 4fe494d
Showing 1 changed file with 6 additions and 5 deletions.
Expand Up @@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;

import org.jboss.logging.Logger;

Expand Down Expand Up @@ -68,7 +69,7 @@ public class DriverManagerConnectionProviderImpl
private boolean autocommit;

private final ArrayList<Connection> pool = new ArrayList<Connection>();
private int checkedOut = 0;
private final AtomicInteger checkedOut = new AtomicInteger();

private boolean stopped;

Expand Down Expand Up @@ -170,7 +171,7 @@ public void stop() {

public Connection getConnection() throws SQLException {
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...
synchronized (pool) {
Expand All @@ -184,7 +185,7 @@ public Connection getConnection() throws SQLException {
if ( pooled.getAutoCommit() != autocommit ) {
pooled.setAutoCommit( autocommit );
}
checkedOut++;
checkedOut.incrementAndGet();
return pooled;
}
}
Expand All @@ -206,12 +207,12 @@ public Connection getConnection() throws SQLException {
LOG.debugf( "Created connection to: %s, Isolation Level: %s", url, conn.getTransactionIsolation() );
}

checkedOut++;
checkedOut.incrementAndGet();
return conn;
}

public void closeConnection(Connection conn) throws SQLException {
checkedOut--;
checkedOut.decrementAndGet();

final boolean traceEnabled = LOG.isTraceEnabled();
// add to the pool if the max size is not yet reached.
Expand Down

0 comments on commit 4fe494d

Please sign in to comment.