You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Phil Steitz <ph...@gmail.com> on 2011/12/23 07:46:32 UTC

Re: svn commit: r1214517 - in /commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl: GenericKeyedObjectPool.java GenericObjectPool.java

These counts only count threads waiting on the Deques.  We don't
track factory methods in progress other than creates; but it looks
to me like the estimate could be made more accurate by adding (in
GOP case) createCount - createdCount.  This is probably not that
important in practice, unless the pool has screwy settings leading
to lots of object churn.  A more likely scenario leading to negative
bias is high validation latency.  We might want to consider tracking
the number of validations in progress.

Phil

On 12/14/11 3:47 PM, markt@apache.org wrote:
> Author: markt
> Date: Wed Dec 14 22:47:17 2011
> New Revision: 1214517
>
> URL: http://svn.apache.org/viewvc?rev=1214517&view=rev
> Log:
> Fix POOL-159. Expose (an estimate of) the number of threads blocked waiting for an object from the pool.
>
> Modified:
>     commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
>     commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java
>
> Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
> URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java?rev=1214517&r1=1214516&r2=1214517&view=diff
> ==============================================================================
> --- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java (original)
> +++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java Wed Dec 14 22:47:17 2011
> @@ -1816,6 +1816,50 @@ public class GenericKeyedObjectPool<K,T>
>          return maxBorrowWaitTimeMillis;
>      }
>  
> +    /**
> +     * Return an estimate of the number of threads currently blocked waiting for
> +     * an object from the pool. This is intended for monitoring only, not for
> +     * synchronization control.
> +     * 
> +     * @return  An estimate of the number of threads currently blocked waiting
> +     *          for an object from the pool 
> +     */
> +    public int getNumWaiters() {
> +        int result = 0;
> +        
> +        if (getBlockWhenExhausted()) {
> +            Iterator<ObjectDeque<T>> iter = poolMap.values().iterator();
> +            
> +            while (iter.hasNext()) {
> +                // Assume no overflow
> +                result += iter.next().getIdleObjects().getTakeQueueLength();
> +            }
> +        }
> +        
> +        return result;
> +    }
> +    
> +    /**
> +     * Return an estimate of the number of threads currently blocked waiting for
> +     * an object from the pool for the given key. This is intended for
> +     * monitoring only, not for synchronization control.
> +     * 
> +     * @return  An estimate of the number of threads currently blocked waiting
> +     *          for an object from the pool for the given key
> +     */
> +    public int getNumWaiters(K key) {
> +        if (getBlockWhenExhausted()) {
> +            final ObjectDeque<T> objectDeque = poolMap.get(key);
> +            if (objectDeque == null) {
> +                return 0;
> +            } else {
> +                return objectDeque.getIdleObjects().getTakeQueueLength();
> +            }
> +        } else {
> +            return 0;
> +        }
> +    }
> +
>      //--- inner classes ----------------------------------------------
>  
>      /**
>
> Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java
> URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java?rev=1214517&r1=1214516&r2=1214517&view=diff
> ==============================================================================
> --- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java (original)
> +++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java Wed Dec 14 22:47:17 2011
> @@ -1341,6 +1341,22 @@ public class GenericObjectPool<T> extend
>          return maxBorrowWaitTimeMillis;
>      }
>  
> +    /**
> +     * Return an estimate of the number of threads currently blocked waiting for
> +     * an object from the pool. This is intended for monitoring only, not for
> +     * synchronization control.
> +     * 
> +     * @return  An estimate of the number of threads currently blocked waiting
> +     *          for an object from the pool 
> +     */
> +    public int getNumWaiters() {
> +        if (getBlockWhenExhausted()) {
> +            return idleObjects.getTakeQueueLength();
> +        } else {
> +            return 0;
> +        }
> +    }
> +
>      // --- inner classes ----------------------------------------------
>  
>      /**
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org