commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1332583 - /commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
Date Tue, 01 May 2012 09:18:10 GMT
Author: markt
Date: Tue May  1 09:18:09 2012
New Revision: 1332583

URL: http://svn.apache.org/viewvc?rev=1332583&view=rev
Log:
Clarify purposes of locks. (Feedback from sebb)

Modified:
    commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java

Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java?rev=1332583&r1=1332582&r2=1332583&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
Tue May  1 09:18:09 2012
@@ -1001,12 +1001,12 @@ public class GenericKeyedObjectPool<K,T>
                     if (evictionKeyIterator == null ||
                             !evictionKeyIterator.hasNext()) {
                         List<K> keyCopy = new ArrayList<K>();
-                        Lock lock = keyLock.readLock();
-                        lock.lock();
+                        Lock readLock = keyLock.readLock();
+                        readLock.lock();
                         try {
                             keyCopy.addAll(poolKeyList);
                         } finally {
-                            lock.unlock();
+                            readLock.unlock();
                         }
                         evictionKeyIterator = keyCopy.iterator();
                     }
@@ -1188,16 +1188,16 @@ public class GenericKeyedObjectPool<K,T>
      * @see #deregister(Object)
      */
     private ObjectDeque<T> register(K k) {
-        Lock lock = keyLock.readLock();
+        Lock readLock = keyLock.readLock();
         ObjectDeque<T> objectDeque = null;
         try {
-            lock.lock();
+            readLock.lock();
             objectDeque = poolMap.get(k);
             if (objectDeque == null) {
                 // Upgrade to write lock
-                lock.unlock();
-                lock = keyLock.writeLock();
-                lock.lock();
+                readLock.unlock();
+                readLock = keyLock.writeLock();
+                readLock.lock();
                 objectDeque = poolMap.get(k);
                 if (objectDeque == null) {
                     objectDeque = new ObjectDeque<T>();
@@ -1214,7 +1214,7 @@ public class GenericKeyedObjectPool<K,T>
                 objectDeque.getNumInterested().incrementAndGet();
             }
         } finally {
-            lock.unlock();
+            readLock.unlock();
         }
         return objectDeque;
     }
@@ -1238,8 +1238,8 @@ public class GenericKeyedObjectPool<K,T>
         long numInterested = objectDeque.getNumInterested().decrementAndGet();
         if (numInterested == 0 && objectDeque.getCreateCount().get() == 0) {
             // Potential to remove key
-            Lock lock = keyLock.writeLock();
-            lock.lock();
+            Lock writeLock = keyLock.writeLock();
+            writeLock.lock();
             try {
                 if (objectDeque.getCreateCount().get() == 0 &&
                         objectDeque.getNumInterested().get() == 0) {
@@ -1250,7 +1250,7 @@ public class GenericKeyedObjectPool<K,T>
                     poolKeyList.remove(k);
                 }
             } finally {
-                lock.unlock();
+                writeLock.unlock();
             }
         }
     }
@@ -1499,12 +1499,12 @@ public class GenericKeyedObjectPool<K,T>
     @Override
     public List<K> getKeys() {
         List<K> keyCopy = new ArrayList<K>();
-        Lock lock = keyLock.readLock();
-        lock.lock();
+        Lock readLock = keyLock.readLock();
+        readLock.lock();
         try {
             keyCopy.addAll(poolKeyList);
         } finally {
-            lock.unlock();
+            readLock.unlock();
         }
         return keyCopy;
     }



Mime
View raw message