You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Guido Schmutz <Gu...@trivadis.com> on 2010/03/18 07:43:17 UTC
UNLIST
UNLIST
Guido Schmutz
Technology Manager Integration,
Common and Open Source based Development
Partner / Principal Consultant
Application Development
Trivadis AG
Papiermühlestrasse 73
CH-3014 Bern
Phone +41-31-928 09 60
Fax +41-31-928 09 64
Mobile +41-79-412 05 39
guido.schmutz@trivadis.com
www.trivadis.com
Blog: http://guidoschmutz.wordpress.com
-----Original Message-----
From: markt@apache.org [mailto:markt@apache.org]
Sent: Mittwoch, 17. März 2010 21:41
To: commits@commons.apache.org
Subject: svn commit: r924479 - in /commons/proper/pool/trunk/src: java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java java/org/apache/commons/pool/impl/GenericObjectPool.java test/org/apache/commons/pool/impl/TestGenericObjectPool.java
Author: markt
Date: Wed Mar 17 20:40:42 2010
New Revision: 924479
URL: http://svn.apache.org/viewvc?rev=924479&view=rev
Log:
Provide a test case and fix POOL-162 based on Phil's suggestion.
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/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.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=924479&r1=924478&r2=924479&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 Mar 17 20:40:42 2010
@@ -1149,9 +1149,18 @@ 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
+ if (latch.getPair() == null && !latch.mayCreate()) {
+ _allocationQueue.remove(latch);
+ } else {
+ break;
+ }
+ }
Thread.currentThread().interrupt();
throw e;
- }
+ }
if (maxWait > 0 && ((System.currentTimeMillis() - starttime) >= maxWait)) {
synchronized (this) {
// Make sure allocate hasn't already assigned an object
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=924479&r1=924478&r2=924479&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 Wed Mar 17 20:40:42 2010
@@ -1117,6 +1117,16 @@ 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
+ if (latch.getPair() == null && !latch.mayCreate()) {
+ // Remove latch from the allocation queue
+ _allocationQueue.remove(latch);
+ } else {
+ break;
+ }
+ }
Thread.currentThread().interrupt();
throw e;
}
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java?rev=924479&r1=924478&r2=924479&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java Wed Mar 17 20:40:42 2010
@@ -110,6 +110,46 @@ public class TestGenericObjectPool exten
pool.close();
}
+ public void testWhenExhaustedBlockInterupt() throws Exception {
+ pool.setMaxActive(1);
+ pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
+ pool.setMaxWait(0);
+ Object obj1 = pool.borrowObject();
+
+ // Make sure on object was obtained
+ assertNotNull(obj1);
+
+ // Create a separate thread to try and borrow another object
+ WaitingTestThread wtt = new WaitingTestThread(pool, 200);
+ wtt.start();
+ // Give wtt time to start
+ Thread.sleep(200);
+ wtt.interrupt();
+
+ // Give interupt time to take effect
+ Thread.sleep(200);
+
+ // Check thread was interrupted
+ assertTrue(wtt._thrown instanceof InterruptedException);
+
+ // Return object to the pool
+ pool.returnObject(obj1);
+
+ // Bug POOL-162 - check there is now an object in the pool
+ pool.setMaxWait(10L);
+ Object obj2 = null;
+ try {
+ obj2 = pool.borrowObject();
+ assertNotNull(obj2);
+ } catch(NoSuchElementException e) {
+ // Not expected
+ fail("NoSuchElementException not expected");
+ }
+ pool.returnObject(obj2);
+ pool.close();
+
+ }
+
public void testEvictWhileEmpty() throws Exception {
pool.evict();
pool.evict();