You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2009/07/02 14:56:45 UTC

svn commit: r790572 - in /commons/proper/pool/trunk: src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java src/java/org/apache/commons/pool/impl/GenericObjectPool.java xdocs/changes.xml

Author: markt
Date: Thu Jul  2 12:56:45 2009
New Revision: 790572

URL: http://svn.apache.org/viewvc?rev=790572&view=rev
Log:
Fix POOL-147.
It was possible for a thread to enter an infinite wait when it had already been allocated an object

Modified:
    commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
    commons/proper/pool/trunk/xdocs/changes.xml

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=790572&r1=790571&r2=790572&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 Thu Jul  2 12:56:45 2009
@@ -1127,17 +1127,22 @@
                         case WHEN_EXHAUSTED_BLOCK:
                             try {
                                 synchronized (latch) {
-                                    if (maxWait <= 0) {
-                                        latch.wait();
-                                    } else {
-                                        // this code may be executed again after a notify then continue cycle
-                                        // so, need to calculate the amount of time to wait
-                                        final long elapsed = (System.currentTimeMillis() - starttime);
-                                        final long waitTime = maxWait - elapsed;
-                                        if (waitTime > 0)
-                                        {
-                                            latch.wait(waitTime);
+                                    // Before we wait, make sure another thread didn't allocate us an object
+                                    if (latch.getPair() == null) {
+                                        if (maxWait <= 0) {
+                                            latch.wait();
+                                        } else {
+                                            // this code may be executed again after a notify then continue cycle
+                                            // so, need to calculate the amount of time to wait
+                                            final long elapsed = (System.currentTimeMillis() - starttime);
+                                            final long waitTime = maxWait - elapsed;
+                                            if (waitTime > 0)
+                                            {
+                                                latch.wait(waitTime);
+                                            }
                                         }
+                                    } else {
+                                        break;
                                     }
                                 }
                             } catch(InterruptedException e) {

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java?rev=790572&r1=790571&r2=790572&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java Thu Jul  2 12:56:45 2009
@@ -1095,17 +1095,22 @@
                         case WHEN_EXHAUSTED_BLOCK:
                             try {
                                 synchronized (latch) {
-                                    if(maxWait <= 0) {
-                                        latch.wait();
-                                    } else {
-                                        // this code may be executed again after a notify then continue cycle
-                                        // so, need to calculate the amount of time to wait
-                                        final long elapsed = (System.currentTimeMillis() - starttime);
-                                        final long waitTime = maxWait - elapsed;
-                                        if (waitTime > 0)
-                                        {
-                                            latch.wait(waitTime);
+                                    // Before we wait, make sure another thread didn't allocate us an object
+                                    if (latch.getPair() == null) {
+                                        if(maxWait <= 0) {
+                                            latch.wait();
+                                        } else {
+                                            // this code may be executed again after a notify then continue cycle
+                                            // so, need to calculate the amount of time to wait
+                                            final long elapsed = (System.currentTimeMillis() - starttime);
+                                            final long waitTime = maxWait - elapsed;
+                                            if (waitTime > 0)
+                                            {
+                                                latch.wait(waitTime);
+                                            }
                                         }
+                                    } else {
+                                        break;
                                     }
                                 }
                             } catch(InterruptedException e) {

Modified: commons/proper/pool/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/xdocs/changes.xml?rev=790572&r1=790571&r2=790572&view=diff
==============================================================================
--- commons/proper/pool/trunk/xdocs/changes.xml (original)
+++ commons/proper/pool/trunk/xdocs/changes.xml Thu Jul  2 12:56:45 2009
@@ -23,6 +23,10 @@
   <body>
 
   <release version="1.5.2" date="TBD">
+    <action dev="markt" type="fix" issue="POOL-147" due-to="Giambattista Bloisi">
+      Fix case where a thread could end up waiting indefinitely even if objects
+      were available.
+    </action>
   </release>
   <release version="1.5.1" date="2009-06-16" description=
 "This is a patch release containing a fix for POOL-144, a regression introduced