| File |
Line |
| org/apache/commons/pool/impl/GenericKeyedObjectPool.java |
808 |
| org/apache/commons/pool/impl/GenericObjectPool.java |
749 |
}
/**
* Returns the minimum number of objects allowed in the pool
* before the evictor thread (if active) spawns new objects.
* (Note no objects are created when: numActive + numIdle >= maxActive)
*
* @return The minimum number of objects.
* @see #setMinIdle
*/
public synchronized int getMinIdle() {
return _minIdle;
}
/**
* When <tt>true</tt>, objects will be
* {@link PoolableObjectFactory#validateObject validated}
* before being returned by the {@link #borrowObject}
* method. If the object fails to validate,
* it will be dropped from the pool, and we will attempt
* to borrow another.
*
* @return <code>true</code> if objects are validated before being borrowed.
* @see #setTestOnBorrow
*/
public boolean getTestOnBorrow() {
return _testOnBorrow;
}
/**
* When <tt>true</tt>, objects will be
* {@link PoolableObjectFactory#validateObject validated}
* before being returned by the {@link #borrowObject}
* method. If the object fails to validate,
* it will be dropped from the pool, and we will attempt
* to borrow another.
*
* @param testOnBorrow <code>true</code> if objects should be validated before being borrowed.
* @see #getTestOnBorrow
*/
public void setTestOnBorrow(boolean testOnBorrow) {
_testOnBorrow = testOnBorrow;
}
/**
* When <tt>true</tt>, objects will be
* {@link PoolableObjectFactory#validateObject validated}
* before being returned to the pool within the
* {@link #returnObject}.
*
* @return <code>true</code> when objects will be validated after returned to {@link #returnObject}.
* @see #setTestOnReturn
*/
public boolean getTestOnReturn() {
return _testOnReturn;
}
/**
* When <tt>true</tt>, objects will be
* {@link PoolableObjectFactory#validateObject validated}
* before being returned to the pool within the
* {@link #returnObject}.
*
* @param testOnReturn <code>true</code> so objects will be validated after returned to {@link #returnObject}.
* @see #getTestOnReturn
*/
public void setTestOnReturn(boolean testOnReturn) {
_testOnReturn = testOnReturn;
}
/**
* Returns the number of milliseconds to sleep between runs of the
* idle object evictor thread.
* When non-positive, no idle object evictor thread will be
* run.
*
* @return number of milliseconds to sleep between evictor runs.
* @see #setTimeBetweenEvictionRunsMillis
*/
public synchronized long getTimeBetweenEvictionRunsMillis() {
return _timeBetweenEvictionRunsMillis;
}
/**
* Sets the number of milliseconds to sleep between runs of the
* idle object evictor thread.
* When non-positive, no idle object evictor thread will be
* run.
*
* @param timeBetweenEvictionRunsMillis number of milliseconds to sleep between evictor runs.
* @see #getTimeBetweenEvictionRunsMillis
*/
public synchronized void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
_timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
startEvictor(_timeBetweenEvictionRunsMillis);
}
/**
* Returns the max number of objects to examine during each run of the
* idle object evictor thread (if any).
*
* @return max number of objects to examine during each evictor run.
* @see #setNumTestsPerEvictionRun
* @see #setTimeBetweenEvictionRunsMillis
*/
public synchronized int getNumTestsPerEvictionRun() {
return _numTestsPerEvictionRun;
}
/**
* Sets the max number of objects to examine during each run of the
* idle object evictor thread (if any).
* <p>
* When a negative value is supplied, <tt>ceil({@link #getNumIdle})/abs({@link #getNumTestsPerEvictionRun})</tt>
* tests will be run. That is, when the value is <i>-n</i>, roughly one <i>n</i>th of the
* idle objects will be tested per run. When the value is positive, the number of tests
* actually performed in each run will be the minimum of this value and the number of instances
* idle in the pool.
*
* @param numTestsPerEvictionRun max number of objects to examine during each evictor run.
* @see #getNumTestsPerEvictionRun
* @see #setTimeBetweenEvictionRunsMillis
*/
public synchronized void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
_numTestsPerEvictionRun = numTestsPerEvictionRun;
}
/**
* Returns the minimum amount of time an object may sit idle in the pool
* before it is eligible for eviction by the idle object evictor
* (if any).
*
* @return minimum amount of time an object may sit idle in the pool before it is eligible for eviction.
* @see #setMinEvictableIdleTimeMillis
* @see #setTimeBetweenEvictionRunsMillis
*/
public synchronized long getMinEvictableIdleTimeMillis() {
return _minEvictableIdleTimeMillis;
}
/**
* Sets the minimum amount of time an object may sit idle in the pool
* before it is eligible for eviction by the idle object evictor
* (if any).
* When non-positive, no objects will be evicted from the pool
* due to idle time alone.
* @param minEvictableIdleTimeMillis minimum amount of time an object may sit idle in the pool before
* it is eligible for eviction.
* @see #getMinEvictableIdleTimeMillis
* @see #setTimeBetweenEvictionRunsMillis
*/
public synchronized void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
_minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
}
/**
* Returns the minimum amount of time an object may sit idle in the pool
* before it is eligible for eviction by the idle object evictor
* (if any), with the extra condition that at least
* "minIdle" amount of object remain in the pool.
*
* @return minimum amount of time an object may sit idle in the pool before it is eligible for eviction.
* @since Pool 1.3
* @see #setSoftMinEvictableIdleTimeMillis
*/
public synchronized long getSoftMinEvictableIdleTimeMillis() {
|
| File |
Line |
| org/apache/commons/pool/PoolUtils.java |
834 |
| org/apache/commons/pool/PoolUtils.java |
1432 |
}
}
public void addObject() throws Exception, IllegalStateException, UnsupportedOperationException {
pool.addObject();
}
public int getNumIdle() throws UnsupportedOperationException {
return pool.getNumIdle();
}
public int getNumActive() throws UnsupportedOperationException {
return pool.getNumActive();
}
public void clear() throws Exception, UnsupportedOperationException {
pool.clear();
}
public void close() {
try {
pool.close();
} catch (Exception e) {
// swallowed
}
}
public void setFactory(final PoolableObjectFactory factory) throws IllegalStateException, UnsupportedOperationException {
pool.setFactory(factory);
}
public String toString() {
|
| File |
Line |
| org/apache/commons/pool/impl/SoftReferenceObjectPool.java |
101 |
| org/apache/commons/pool/impl/StackObjectPool.java |
155 |
}
if (null != _factory && null != obj) {
try {
_factory.activateObject(obj);
if (!_factory.validateObject(obj)) {
throw new Exception("ValidateObject failed");
}
} catch (Throwable t) {
try {
_factory.destroyObject(obj);
} catch (Throwable t2) {
// swallowed
} finally {
obj = null;
}
if (newlyCreated) {
throw new NoSuchElementException(
"Could not create a validated object, cause: " +
t.getMessage());
}
}
}
}
_numActive++;
return obj;
}
public synchronized void returnObject(Object obj) throws Exception {
boolean success = !isClosed();
if(null != _factory) {
|
| File |
Line |
| org/apache/commons/pool/impl/GenericKeyedObjectPool.java |
2043 |
| org/apache/commons/pool/impl/GenericObjectPool.java |
1626 |
}
}
//--- non-public methods ----------------------------------------
/**
* Start the eviction thread or service, or when
* <i>delay</i> is non-positive, stop it
* if it is already running.
*
* @param delay milliseconds between evictor runs.
*/
protected synchronized void startEvictor(long delay) {
if(null != _evictor) {
EvictionTimer.cancel(_evictor);
_evictor = null;
}
if(delay > 0) {
_evictor = new Evictor();
EvictionTimer.schedule(_evictor, delay, delay);
}
}
/**
* Returns pool info including {@link #getNumActive()}, {@link #getNumIdle()}
* and a list of objects idle in the pool with their idle times.
*
* @return string containing debug information
*/
synchronized String debugInfo() {
StringBuffer buf = new StringBuffer();
buf.append("Active: ").append(getNumActive()).append("\n");
buf.append("Idle: ").append(getNumIdle()).append("\n");
|