/** * Sets the cap on the number of objects that can be allocated by the pool * (checked out to clients, or idle awaiting checkout) at a given time. Use * a negative value for no limit. * * @param maxActive The cap on the total number of object instances managed by the pool. * Negative values mean that there is no limit to the number of objects allocated * by the pool. * @see #getMaxActive */ public void setMaxActive(int maxActive) { synchronized(this) { _maxActive = maxActive; } allocate(); }
/** * Sets the minimum number of objects allowed in the pool * before the evictor thread (if active) spawns new objects. * Note that no objects are created when * <code>numActive + numIdle >= maxActive.</code> * This setting has no effect if the idle object evictor is disabled * (i.e. if <code>timeBetweenEvictionRunsMillis <= 0</code>). * * @param minIdle The minimum number of objects. * @see #getMinIdle * @see #getTimeBetweenEvictionRunsMillis() */ public void setMinIdle(int minIdle) { synchronized(this) { _minIdle = minIdle; } allocate(); }
/** * Sets the cap on the number of "idle" instances in the pool. * If maxIdle is set too low on heavily loaded systems it is possible you * will see objects being destroyed and almost immediately new objects * being created. This is a result of the active threads momentarily * returning objects faster than they are requesting them them, causing the * number of idle objects to rise above maxIdle. The best value for maxIdle * for heavily loaded system will vary but the default is a good starting * point. * @param maxIdle The cap on the number of "idle" instances in the pool. * Use a negative value to indicate an unlimited number of idle instances. * @see #getMaxIdle */ public void setMaxIdle(int maxIdle) { synchronized(this) { _maxIdle = maxIdle; } allocate(); }
/** * Sets the maximum amount of time (in milliseconds) the * {@link #borrowObject} method should block before throwing * an exception when the pool is exhausted and the * {@link #setWhenExhaustedAction "when exhausted" action} is * {@link #WHEN_EXHAUSTED_BLOCK}. * * When less than or equal to 0, the {@link #borrowObject} method * may block indefinitely. * * @param maxWait maximum number of milliseconds to block when borrowing an object. * @see #getMaxWait * @see #setWhenExhaustedAction * @see #WHEN_EXHAUSTED_BLOCK */ public void setMaxWait(long maxWait) { synchronized(this) { _maxWait = maxWait; } allocate(); }
/** * Sets the action to take when the {@link #borrowObject} method * is invoked when the pool is exhausted (the maximum number * of "active" objects has been reached). * * @param whenExhaustedAction the action code, which must be one of * {@link #WHEN_EXHAUSTED_BLOCK}, {@link #WHEN_EXHAUSTED_FAIL}, * or {@link #WHEN_EXHAUSTED_GROW} * @see #getWhenExhaustedAction */ public void setWhenExhaustedAction(byte whenExhaustedAction) { synchronized(this) { switch(whenExhaustedAction) { case WHEN_EXHAUSTED_BLOCK: case WHEN_EXHAUSTED_FAIL: case WHEN_EXHAUSTED_GROW: _whenExhaustedAction = whenExhaustedAction; break; default: throw new IllegalArgumentException("whenExhaustedAction " + whenExhaustedAction + " not recognized."); } } allocate(); }
/** * {@inheritDoc} * <p>Activation of this method decrements the active count and attempts to destroy the instance.</p> * * @throws Exception if the configured {@link PoolableObjectFactory} throws an exception destroying obj */ @Override public void invalidateObject(T obj) throws Exception { try { if (_factory != null) { _factory.destroyObject(obj); } } finally { synchronized (this) { _numActive--; } allocate(); } }
/** * Private method to destroy all the objects in a collection using the * supplied object factory. Assumes that objects in the collection are * instances of ObjectTimestampPair and that the object instances that * they wrap were created by the factory. * * @param c Collection of objects to destroy * @param factory PoolableConnectionFactory used to destroy the objects */ private void destroy(Collection<ObjectTimestampPair<T>> c, PoolableObjectFactory<T> factory) { for (Iterator<ObjectTimestampPair<T>> it = c.iterator(); it.hasNext();) { try { factory.destroyObject(it.next().value); } catch(Exception e) { // ignore error, keep destroying the rest } finally { synchronized(this) { _numInternalProcessing--; } allocate(); } } }
_numActive--; allocate();
/** * Check to see if we are below our minimum number of objects * if so enough to bring us back to our minimum. * * @throws Exception when {@link #addObject()} fails. */ private void ensureMinIdle() throws Exception { // this method isn't synchronized so the // calculateDeficit is done at the beginning // as a loop limit and a second time inside the loop // to stop when another thread already returned the // needed objects int objectDeficit = calculateDeficit(false); for ( int j = 0 ; j < objectDeficit && calculateDeficit(true) > 0 ; j++ ) { try { addObject(); } finally { synchronized (this) { _numInternalProcessing--; } allocate(); } } }
/** * Sets my configuration. * * @param conf configuration to use. * @see GenericObjectPool.Config */ public void setConfig(GenericObjectPool.Config conf) { synchronized (this) { setMaxIdle(conf.maxIdle); setMinIdle(conf.minIdle); setMaxActive(conf.maxActive); setMaxWait(conf.maxWait); setWhenExhaustedAction(conf.whenExhaustedAction); setTestOnBorrow(conf.testOnBorrow); setTestOnReturn(conf.testOnReturn); setTestWhileIdle(conf.testWhileIdle); setNumTestsPerEvictionRun(conf.numTestsPerEvictionRun); setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis); setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis); setSoftMinEvictableIdleTimeMillis(conf.softMinEvictableIdleTimeMillis); setLifo(conf.lifo); } allocate(); }
/** * Sets the cap on the number of objects that can be allocated by the pool * (checked out to clients, or idle awaiting checkout) at a given time. Use * a negative value for no limit. * * @param maxActive The cap on the total number of object instances managed by the pool. * Negative values mean that there is no limit to the number of objects allocated * by the pool. * @see #getMaxActive */ public synchronized void setMaxActive(int maxActive) { _maxActive = maxActive; allocate(); }
/** * Sets the cap on the number of objects that can be allocated by the pool * (checked out to clients, or idle awaiting checkout) at a given time. Use * a negative value for no limit. * * @param maxActive The cap on the total number of object instances managed by the pool. * Negative values mean that there is no limit to the number of objects allocated * by the pool. * @see #getMaxActive */ public synchronized void setMaxActive(int maxActive) { _maxActive = maxActive; allocate(); }
/** * Sets the cap on the number of objects that can be allocated by the pool * (checked out to clients, or idle awaiting checkout) at a given time. Use * a negative value for no limit. * * @param maxActive The cap on the total number of object instances managed by the pool. * Negative values mean that there is no limit to the number of objects allocated * by the pool. * @see #getMaxActive */ public void setMaxActive(int maxActive) { synchronized(this) { _maxActive = maxActive; } allocate(); }
/** * Sets the minimum number of objects allowed in the pool * before the evictor thread (if active) spawns new objects. * Note that no objects are created when * <code>numActive + numIdle >= maxActive.</code> * This setting has no effect if the idle object evictor is disabled * (i.e. if <code>timeBetweenEvictionRunsMillis <= 0</code>). * * @param minIdle The minimum number of objects. * @see #getMinIdle * @see #getTimeBetweenEvictionRunsMillis() */ public synchronized void setMinIdle(int minIdle) { _minIdle = minIdle; allocate(); }
/** * Sets the minimum number of objects allowed in the pool * before the evictor thread (if active) spawns new objects. * Note that no objects are created when * <code>numActive + numIdle >= maxActive.</code> * This setting has no effect if the idle object evictor is disabled * (i.e. if <code>timeBetweenEvictionRunsMillis <= 0</code>). * * @param minIdle The minimum number of objects. * @see #getMinIdle * @see #getTimeBetweenEvictionRunsMillis() */ public synchronized void setMinIdle(int minIdle) { _minIdle = minIdle; allocate(); }
/** * Sets the cap on the number of objects that can be allocated by the pool * (checked out to clients, or idle awaiting checkout) at a given time. Use * a negative value for no limit. * * @param maxActive The cap on the total number of object instances managed by the pool. * Negative values mean that there is no limit to the number of objects allocated * by the pool. * @see #getMaxActive */ public void setMaxActive(int maxActive) { synchronized(this) { _maxActive = maxActive; } allocate(); }
/** * Sets the maximum amount of time (in milliseconds) the * {@link #borrowObject} method should block before throwing * an exception when the pool is exhausted and the * {@link #setWhenExhaustedAction "when exhausted" action} is * {@link #WHEN_EXHAUSTED_BLOCK}. * * When less than or equal to 0, the {@link #borrowObject} method * may block indefinitely. * * @param maxWait maximum number of milliseconds to block when borrowing an object. * @see #getMaxWait * @see #setWhenExhaustedAction * @see #WHEN_EXHAUSTED_BLOCK */ public synchronized void setMaxWait(long maxWait) { _maxWait = maxWait; allocate(); }