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 2012/04/10 23:12:46 UTC

svn commit: r1311993 - in /commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl: InterruptibleReentrantLock.java LinkedBlockingDeque.java

Author: markt
Date: Tue Apr 10 21:12:45 2012
New Revision: 1311993

URL: http://svn.apache.org/viewvc?rev=1311993&view=rev
Log:
Add the ability to interrupt threads waiting to remove an object from the queue. This is required to re-fix POOL-189 for pool2 since the (currently disabled) associated test case fails at the moment.

Added:
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/InterruptibleReentrantLock.java   (with props)
Modified:
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java

Added: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/InterruptibleReentrantLock.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/InterruptibleReentrantLock.java?rev=1311993&view=auto
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/InterruptibleReentrantLock.java (added)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/InterruptibleReentrantLock.java Tue Apr 10 21:12:45 2012
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.pool2.impl;
+
+import java.util.Collection;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.ReentrantLock;
+
+public class InterruptibleReentrantLock extends ReentrantLock {
+
+    private static final long serialVersionUID = 1L;
+
+    public void interruptWaiters(Condition condition) {
+        Collection<Thread> threads = getWaitingThreads(condition);
+        for (Thread thread : threads) {
+            thread.interrupt();
+        }
+    }
+}

Propchange: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/InterruptibleReentrantLock.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java?rev=1311993&r1=1311992&r2=1311993&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java Tue Apr 10 21:12:45 2012
@@ -138,7 +138,8 @@ public class LinkedBlockingDeque<E>
     private final int capacity;
 
     /** Main lock guarding all access */
-    private final ReentrantLock lock = new ReentrantLock();
+    private final InterruptibleReentrantLock lock =
+            new InterruptibleReentrantLock();
 
     /** Condition for waiting takes */
     private final Condition notEmpty = lock.newCondition();
@@ -1197,7 +1198,19 @@ public class LinkedBlockingDeque<E>
         } finally {
             lock.unlock();
         }     
-        
     }
 
+    /**
+     * Interrupts the threads currently waiting to take an object from the pool.
+     * See disclaimer on accuracy in
+     * {@link ReentrantLock#getWaitingThreads(Condition)}.
+     */
+    public void interuptTakeWaiters() {
+        lock.lock();
+        try {
+           lock.interruptWaiters(notEmpty);
+        } finally {
+            lock.unlock();
+        }     
+    }
 }



Re: svn commit: r1311993 - in /commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl: InterruptibleReentrantLock.java LinkedBlockingDeque.java

Posted by Mark Thomas <ma...@apache.org>.
On 10/04/2012 22:12, markt@apache.org wrote:
> Author: markt Date: Tue Apr 10 21:12:45 2012 New Revision: 1311993
> 
> URL: http://svn.apache.org/viewvc?rev=1311993&view=rev
> Log: Add the ability to interrupt threads waiting to remove an object
> from the queue. This is required to re-fix POOL-189 for pool2 since the
> (currently disabled) associated test case fails at the moment.

I have the GOP fix for this locally. Unfortunately it is mixed up with
some changes for POOL-131 that lead to some clean up in the unit tests,
which lead to finding some disabled tests, which lead to discovering
POOL-189 needed re-fixing.

I need to a) unpick the separate changes as best I can and b) make the
same changes for GKOP. My intention is to commit changes to GOP and GKOP
together once I have unpicked what I currently have.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org