commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1084557 - in /commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl: GenericKeyedObjectPool.java GenericObjectPool.java
Date Wed, 23 Mar 2011 12:08:15 GMT
Author: markt
Date: Wed Mar 23 12:08:15 2011
New Revision: 1084557

URL: http://svn.apache.org/viewvc?rev=1084557&view=rev
Log:
Fix POOL-179. Correctly handle InterruptedException whilst waiting for an object from the
pool.
Based on a suggested patch by Axel GroƟmann

Modified:
    commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
    commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericObjectPool.java

Modified: commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java?rev=1084557&r1=1084556&r2=1084557&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
(original)
+++ commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
Wed Mar 23 12:08:15 2011
@@ -1152,12 +1152,21 @@ public class GenericKeyedObjectPool exte
                                 }
                             } catch(InterruptedException e) {
                                 synchronized (this) {
-                                    // Make sure allocate hasn't already assigned an object
-                                    // in a different thread or permitted a new object to
be created
+                                    // Need to handle the all three possibilities
                                     if (latch.getPair() == null && !latch.mayCreate())
{
+                                        // Case 1: latch still in allocation queue
+                                        // Remove latch from the allocation queue
                                         _allocationQueue.remove(latch);
+                                    } else if (latch.getPair() == null && latch.mayCreate())
{
+                                        // Case 2: latch has been given permission to create
+                                        //         a new object
+                                        latch.getPool().decrementInternalProcessingCount();
+                                        allocate();
                                     } else {
-                                        break;
+                                        // Case 3: An object has been allocated
+                                        latch.getPool().decrementInternalProcessingCount();
+                                        latch.getPool().incrementActiveCount();
+                                        returnObject(latch.getkey(), latch.getPair().getValue());
                                     }
                                 }
                                 Thread.currentThread().interrupt();

Modified: commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericObjectPool.java?rev=1084557&r1=1084556&r2=1084557&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
(original)
+++ commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
Wed Mar 23 12:08:15 2011
@@ -1118,13 +1118,21 @@ public class GenericObjectPool extends B
                                 }
                             } catch(InterruptedException e) {
                                 synchronized(this) {
-                                    // Make sure allocate hasn't already assigned an object
-                                    // in a different thread or permitted a new object to
be created
+                                    // Need to handle the all three possibilities
                                     if (latch.getPair() == null && !latch.mayCreate())
{
+                                        // Case 1: latch still in allocation queue
                                         // Remove latch from the allocation queue
                                         _allocationQueue.remove(latch);
+                                    } else if (latch.getPair() == null && latch.mayCreate())
{
+                                        // Case 2: latch has been given permission to create
+                                        //         a new object
+                                        _numInternalProcessing--;
+                                        allocate();
                                     } else {
-                                        break;
+                                        // Case 3: An object has been allocated
+                                        _numInternalProcessing--;
+                                        _numActive++;
+                                        returnObject(latch.getPair().getValue());
                                     }
                                 }
                                 Thread.currentThread().interrupt();



Mime
View raw message