//===============================================================================
// INSTANCE/QUICK ACCESS VARIABLE
//===============================================================================
-
+ private AtomicInteger size = new AtomicInteger(0);
/**
* All the information about the connection pool
*/
* @return int
*/
public int getSize() {
- return idle.size()+busy.size();
+ return size.get();
}
/**
if (jmxPool!=null) {
jmxPool.notify(org.apache.tomcat.jdbc.pool.jmx.ConnectionPool.NOTIFY_ABANDON, trace);
}
- con.abandon();
+ release(con);
//we've asynchronously reduced the number of connections
//we could have threads stuck in idle.poll(timeout) that will never be notified
if (waitcount.get()>0) idle.offer(new PooledConnection(poolProperties,this));
con.lock();
con.release();
} finally {
+ size.addAndGet(-1);
con.unlock();
}
}
//this is not 100% accurate since it doesn't use a shared
//atomic variable - a connection can become idle while we are creating
//a new connection
- if (busy.size() < getPoolProperties().getMaxActive()) {
+ if (size.get() < getPoolProperties().getMaxActive()) {
+ size.addAndGet(1);
return createConnection(now, con);
} //end if
continue;
if (!con.validate(PooledConnection.VALIDATE_IDLE)) {
idle.remove(con);
- con.release();
+ release(con);
}
} finally {
con.unlock();
/**
* The underlying database connection
*/
- protected java.sql.Connection connection;
+ private java.sql.Connection connection;
/**
* When we track abandon traces, this string holds the thread dump
*/
- protected String abandonTrace = null;
+ private String abandonTrace = null;
/**
* Timestamp the connection was last 'touched' by the pool
*/
- protected long timestamp;
+ private long timestamp;
/**
* Lock for this connection only
*/
- protected ReentrantReadWriteLock lock = new ReentrantReadWriteLock(false);
+ private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(false);
/**
* Set to true if this connection has been discarded by the pool
*/
- protected boolean discarded = false;
+ private boolean discarded = false;
/**
* The Timestamp when the last time the connect() method was called successfully
*/
- protected volatile long lastConnected = -1;
+ private volatile long lastConnected = -1;
/**
* timestamp to keep track of validation intervals
*/
- protected long lastValidated = System.currentTimeMillis();
+ private volatile long lastValidated = System.currentTimeMillis();
/**
* The instance number for this connection
*/
- protected int instanceCount = 0;
+ private int instanceCount = 0;
/**
* The parent
*/
* so that we don't create a new list of interceptors each time we borrow
* the connection
*/
- protected WeakReference<JdbcInterceptor> handler = null;
+ private WeakReference<JdbcInterceptor> handler = null;
public PooledConnection(PoolProperties prop, ConnectionPool parent) {
this.parent = parent;
}
- protected void connect() throws SQLException {
+ public void connect() throws SQLException {
if (connection != null) {
try {
this.disconnect(false);
return connection!=null;
}
- protected void reconnect() throws SQLException {
+ public void reconnect() throws SQLException {
this.disconnect(false);
this.connect();
} //reconnect
- protected void disconnect(boolean finalize) {
+ private void disconnect(boolean finalize) {
if (isDiscarded()) {
return;
}
} //end if
}
- public boolean abandon() {
- try {
- disconnect(true);
- } catch (Exception x) {
- log.error("", x);
- } //catch
- return false;
- }
-
- protected boolean doValidate(int action) {
+ private boolean doValidate(int action) {
if (action == PooledConnection.VALIDATE_BORROW &&
poolProperties.isTestOnBorrow())
return true;