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();
+ }
+ }
}