commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1215558 - /commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
Date Sat, 17 Dec 2011 19:08:10 GMT
Author: markt
Date: Sat Dec 17 19:08:10 2011
New Revision: 1215558

URL: http://svn.apache.org/viewvc?rev=1215558&view=rev
Log:
Fix POOL-205. Consistent locking for poolKeyList

Modified:
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.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=1215558&r1=1215557&r2=1215558&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
Sat Dec 17 19:08:10 2011
@@ -1299,7 +1299,13 @@ public class GenericKeyedObjectPool<K,T>
                     if (evictionKeyIterator == null ||
                             !evictionKeyIterator.hasNext()) {
                         List<K> keyCopy = new ArrayList<K>();
-                        keyCopy.addAll(poolKeyList);
+                        Lock lock = keyLock.readLock();
+                        lock .lock();
+                        try {
+                            keyCopy.addAll(poolKeyList);
+                        } finally {
+                            lock.unlock();
+                        }
                         evictionKeyIterator = keyCopy.iterator();
                     }
                     while (evictionKeyIterator.hasNext()) {
@@ -2140,7 +2146,7 @@ public class GenericKeyedObjectPool<K,T>
             new ConcurrentHashMap<K,ObjectDeque<T>>(); // @GuardedBy("keyLock")
for write access (and some read access)
     
     /** List of pool keys - used to control eviction order */
-    private final List<K> poolKeyList = new ArrayList<K>(); // @GuardedBy("keyLock")
- except in evict() !?
+    private final List<K> poolKeyList = new ArrayList<K>(); // @GuardedBy("keyLock")
 
     /** Lock used to manage adding/removing of keys */
     private final ReadWriteLock keyLock = new ReentrantReadWriteLock(true);



Mime
View raw message