BlockingBuffer - Fix internal locking code

bug 37028, from Sebastian Bazley

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@312957 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2005-10-11 21:09:15 +00:00
parent 4fd151ac2d
commit 16cd754b19
3 changed files with 11 additions and 6 deletions

View File

@ -94,6 +94,7 @@ If this causes major headaches to anyone please contact commons-dev at jakarta.a
<li>BoundedFifoBuffer - Fix iterator remove bug causing ArrayIndexOutOfBounds error [33071]</li> <li>BoundedFifoBuffer - Fix iterator remove bug causing ArrayIndexOutOfBounds error [33071]</li>
<li>UnboundedFifoBuffer - Fix iterator remove bug causing ArrayIndexOutOfBounds error [35733]</li> <li>UnboundedFifoBuffer - Fix iterator remove bug causing ArrayIndexOutOfBounds error [35733]</li>
<li>UnboundedFifoBuffer - Fix deserialization to work with subsequant object manipulation [35763]</li> <li>UnboundedFifoBuffer - Fix deserialization to work with subsequant object manipulation [35763]</li>
<li>BlockingBuffer - Fix internal locking code (internal fix, no effect on users of BlockingBuffer) [37028]</li>
<li>IteratorChain.remove() - Fix to avoid IllegalStateException when one of the underlying iterators is a FilterIterator [34267]</li> <li>IteratorChain.remove() - Fix to avoid IllegalStateException when one of the underlying iterators is a FilterIterator [34267]</li>
<li>ExtendedProperties.convertProperties() - Fix to handle default properties maps correctly [32204]</li> <li>ExtendedProperties.convertProperties() - Fix to handle default properties maps correctly [32204]</li>
<li>Add casts to avoid some JDK1.5 compilation warnings [35474]</li> <li>Add casts to avoid some JDK1.5 compilation warnings [35474]</li>

View File

@ -147,6 +147,9 @@
<contributor> <contributor>
<name>Nicola Ken Barozzi</name> <name>Nicola Ken Barozzi</name>
</contributor> </contributor>
<contributor>
<name>Sebastian Bazley</name>
</contributor>
<contributor> <contributor>
<name>Ola Berg</name> <name>Ola Berg</name>
</contributor> </contributor>

View File

@ -41,6 +41,7 @@ import org.apache.commons.collections.BufferUnderflowException;
* @author Stephen Colebourne * @author Stephen Colebourne
* @author Janek Bogucki * @author Janek Bogucki
* @author Phil Steitz * @author Phil Steitz
* @author Sebastian Bazley
* @version $Revision$ $Date$ * @version $Revision$ $Date$
* @since Commons Collections 3.0 * @since Commons Collections 3.0
*/ */
@ -76,7 +77,7 @@ public class BlockingBuffer extends SynchronizedBuffer {
public boolean add(Object o) { public boolean add(Object o) {
synchronized (lock) { synchronized (lock) {
boolean result = collection.add(o); boolean result = collection.add(o);
notifyAll(); lock.notifyAll();
return result; return result;
} }
} }
@ -84,7 +85,7 @@ public class BlockingBuffer extends SynchronizedBuffer {
public boolean addAll(Collection c) { public boolean addAll(Collection c) {
synchronized (lock) { synchronized (lock) {
boolean result = collection.addAll(c); boolean result = collection.addAll(c);
notifyAll(); lock.notifyAll();
return result; return result;
} }
} }
@ -93,7 +94,7 @@ public class BlockingBuffer extends SynchronizedBuffer {
synchronized (lock) { synchronized (lock) {
while (collection.isEmpty()) { while (collection.isEmpty()) {
try { try {
wait(); lock.wait();
} catch (InterruptedException e) { } catch (InterruptedException e) {
PrintWriter out = new PrintWriter(new StringWriter()); PrintWriter out = new PrintWriter(new StringWriter());
e.printStackTrace(out); e.printStackTrace(out);
@ -110,7 +111,7 @@ public class BlockingBuffer extends SynchronizedBuffer {
long timeLeft = expiration - System.currentTimeMillis(); long timeLeft = expiration - System.currentTimeMillis();
while (timeLeft > 0 && collection.isEmpty()) { while (timeLeft > 0 && collection.isEmpty()) {
try { try {
wait(timeLeft); lock.wait(timeLeft);
timeLeft = expiration - System.currentTimeMillis(); timeLeft = expiration - System.currentTimeMillis();
} catch(InterruptedException e) { } catch(InterruptedException e) {
PrintWriter out = new PrintWriter(new StringWriter()); PrintWriter out = new PrintWriter(new StringWriter());
@ -129,7 +130,7 @@ public class BlockingBuffer extends SynchronizedBuffer {
synchronized (lock) { synchronized (lock) {
while (collection.isEmpty()) { while (collection.isEmpty()) {
try { try {
wait(); lock.wait();
} catch (InterruptedException e) { } catch (InterruptedException e) {
PrintWriter out = new PrintWriter(new StringWriter()); PrintWriter out = new PrintWriter(new StringWriter());
e.printStackTrace(out); e.printStackTrace(out);
@ -146,7 +147,7 @@ public class BlockingBuffer extends SynchronizedBuffer {
long timeLeft = expiration - System.currentTimeMillis(); long timeLeft = expiration - System.currentTimeMillis();
while (timeLeft > 0 && collection.isEmpty()) { while (timeLeft > 0 && collection.isEmpty()) {
try { try {
wait(timeLeft); lock.wait(timeLeft);
timeLeft = expiration - System.currentTimeMillis(); timeLeft = expiration - System.currentTimeMillis();
} catch(InterruptedException e) { } catch(InterruptedException e) {
PrintWriter out = new PrintWriter(new StringWriter()); PrintWriter out = new PrintWriter(new StringWriter());