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 @@
</properties>
<body>
<release version="1.6.1" date="?" description="">
+ <action dev="ggregory" type="fix" issue="POOL-224" due-to="liviutudor">
+ FindBugs performance warnings on StackKeyedObjectPool.
+ </action>
<action dev="markt" type="fix" issue="POOL-161" due-to="Sylvain Laurent">
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 <K> the type of keys in this pool
* @param <V> the type of objects held in this pool
- *
+ *
* @author Rodney Waldhoff
* @author Sandy McArthur
* @version $Id$
@@ -139,7 +139,7 @@ public class StackKeyedObjectPool<K, V>
/**
* 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<K, V>
* 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<K, V>
/**
* 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<K, V>
/**
* 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<K, V>
_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<K, V>
/**
* Returns the active instance count for the given key.
- *
+ *
* @param key pool key
* @return active count
*/
@@ -511,25 +511,34 @@ public class StackKeyedObjectPool<K, V>
}
/**
+ * 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 <code>Integer</code> 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<K, V>
} 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
|