Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0C5A7D9B4 for ; Mon, 30 Jul 2012 21:12:31 +0000 (UTC) Received: (qmail 25101 invoked by uid 500); 30 Jul 2012 21:12:30 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 25045 invoked by uid 500); 30 Jul 2012 21:12:30 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 25036 invoked by uid 99); 30 Jul 2012 21:12:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Jul 2012 21:12:30 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Jul 2012 21:12:27 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 8A65F23888EA for ; Mon, 30 Jul 2012 21:11:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1367304 - in /commons/proper/pool/branches/POOL_1_X/src: changes/changes.xml java/org/apache/commons/pool/impl/StackKeyedObjectPool.java Date: Mon, 30 Jul 2012 21:11:43 -0000 To: commits@commons.apache.org From: ggregory@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120730211143.8A65F23888EA@eris.apache.org> Author: ggregory Date: Mon Jul 30 21:11:42 2012 New Revision: 1367304 URL: http://svn.apache.org/viewvc?rev=1367304&view=rev Log: [POOL-224] FindBugs performance warnings on StackKeyedObjectPool. Modified: commons/proper/pool/branches/POOL_1_X/src/changes/changes.xml commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java Modified: commons/proper/pool/branches/POOL_1_X/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/changes/changes.xml?rev=1367304&r1=1367303&r2=1367304&view=diff ============================================================================== --- commons/proper/pool/branches/POOL_1_X/src/changes/changes.xml (original) +++ commons/proper/pool/branches/POOL_1_X/src/changes/changes.xml Mon Jul 30 21:11:42 2012 @@ -22,6 +22,9 @@ + + FindBugs performance warnings on StackKeyedObjectPool. + Ensure the evictor thread runs with the same class loader that was in use when the pool was created to ensure that the factory class is visible. Modified: commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java?rev=1367304&r1=1367303&r2=1367304&view=diff ============================================================================== --- commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java (original) +++ commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java Mon Jul 30 21:11:42 2012 @@ -43,7 +43,7 @@ import org.apache.commons.pool.PoolUtils * * @param the type of keys in this pool * @param the type of objects held in this pool - * + * * @author Rodney Waldhoff * @author Sandy McArthur * @version $Id$ @@ -139,7 +139,7 @@ public class StackKeyedObjectPool /** * Borrows an object with the given key. If there are no idle instances under the * given key, a new one is created. - * + * * @param key the pool key * @return keyed poolable object instance */ @@ -199,7 +199,7 @@ public class StackKeyedObjectPool * returning instance to the pool results in {@link #_maxSleeping maxSleeping} * exceeded for the given key, the oldest instance in the idle object pool * is destroyed to make room for the returning instance. - * + * * @param key the pool key * @param obj returning instance */ @@ -405,7 +405,7 @@ public class StackKeyedObjectPool /** * Destroys all instances in the stack and clears the stack. - * + * * @param key key passed to factory when destroying instances * @param stack stack to destroy */ @@ -432,7 +432,7 @@ public class StackKeyedObjectPool /** * Returns a string representation of this StackKeyedObjectPool, including * the number of pools, the keys and the size of each keyed pool. - * + * * @return Keys and pool sizes */ @Override @@ -485,7 +485,7 @@ public class StackKeyedObjectPool _factory = factory; } } - + /** * @return the {@link KeyedPoolableObjectFactory} used by this pool to manage object instances. * @since 1.5.5 @@ -496,7 +496,7 @@ public class StackKeyedObjectPool /** * Returns the active instance count for the given key. - * + * * @param key pool key * @return active count */ @@ -511,25 +511,34 @@ public class StackKeyedObjectPool } /** + * This value is created to be used in {@link #incrementActiveCount(Object)} + * when we increment the active count for a key for the first time + * (and the count becomes 1). + * Since Integer is immutable, we can share this instance + * for all such cases, rather than creating a new object instance each time. + */ + private static final Integer ONE = Integer.valueOf(1); + + /** * Increment the active count for the given key. Also * increments the total active count. - * + * * @param key pool key */ private void incrementActiveCount(K key) { _totActive++; Integer old = _activeCount.get(key); if(null == old) { - _activeCount.put(key,new Integer(1)); + _activeCount.put(key,ONE); } else { - _activeCount.put(key,new Integer(old.intValue() + 1)); + _activeCount.put(key,Integer.valueOf(old.intValue() + 1)); } } /** * Decrements the active count for the given key. * Also decrements the total active count. - * + * * @param key pool key */ private void decrementActiveCount(K key) { @@ -540,11 +549,11 @@ public class StackKeyedObjectPool } else if(active.intValue() <= 1) { _activeCount.remove(key); } else { - _activeCount.put(key, new Integer(active.intValue() - 1)); + _activeCount.put(key, Integer.valueOf(active.intValue() - 1)); } } - + /** * @return map of keyed pools * @since 1.5.5