commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r781288 - /commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
Date Wed, 03 Jun 2009 07:52:20 GMT
Author: markt
Date: Wed Jun  3 07:52:20 2009
New Revision: 781288

URL: http://svn.apache.org/viewvc?rev=781288&view=rev
Log:
Fix root cause of error reported by sebb with testEvictorVisiting() on the dev list.
When adding objects to the toDestroy list, need to remove them from the pool to ensure cursors
are kept up to date. Make all places where this happens consistent with each other and, as
much as possible, GOP as well.

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

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java?rev=781288&r1=781287&r2=781288&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
Wed Jun  3 07:52:20 2009
@@ -1284,12 +1284,17 @@
             for (Iterator it = _poolMap.keySet().iterator(); it.hasNext();) {
                 Object key = it.next();
                 ObjectQueue pool = (ObjectQueue)_poolMap.get(key);
-                toDestroy.put(key, pool.queue);
+                // Copy objects to new list so pool.queue can be cleared inside
+                // the sync
+                List objects = new ArrayList();
+                objects.addAll(pool.queue);
+                toDestroy.put(key, objects);
                 it.remove();
                 _poolList.remove(key);
                 _totalIdle = _totalIdle - pool.queue.size();
                 _totalInternalProcessing =
                     _totalInternalProcessing + pool.queue.size();
+                pool.queue.clear();
             }
         }
         destroy(toDestroy);
@@ -1372,10 +1377,15 @@
             } else {
                 _poolList.remove(key);
             }
+            // Copy objects to new list so pool.queue can be cleared inside
+            // the sync
+            List objects = new ArrayList();
+            objects.addAll(pool.queue);
+            toDestroy.put(key, objects);
             _totalIdle = _totalIdle - pool.queue.size();
             _totalInternalProcessing =
                 _totalInternalProcessing + pool.queue.size();
-            toDestroy.put(key, pool.queue);
+            pool.queue.clear();
         }
         destroy(toDestroy);
     }
@@ -1701,12 +1711,17 @@
                     Object key = it.next();
                     ObjectQueue pool = (ObjectQueue)_poolMap.get(key);
                     if (pool != null) {
-                        toDestroy.put(key, pool.queue);
+                        // Copy objects to new list so pool.queue can be cleared
+                        // inside the sync
+                        List objects = new ArrayList();
+                        objects.addAll(pool.queue);
+                        toDestroy.put(key, objects);
                         it.remove();
                         _poolList.remove(key);
                         _totalIdle = _totalIdle - pool.queue.size();
                         _totalInternalProcessing =
                             _totalInternalProcessing + pool.queue.size();
+                        pool.queue.clear();
                     }
                 }
                 _factory = factory;



Mime
View raw message