[concurrency-interest] JCiP Condition Queues

Alexandru Popescu the.mindstorm.mailinglist at gmail.com
Sat Nov 4 04:53:37 EST 2006


I have made my way through the Chapter 14 (the book is great, the time
is limited :-)) . At the end of 14.2.4 subchapter I have found the
following code:

[code - page: 304]
public synchronized void put(V v) throws InterruptedException {
    while (isFull()) wait();

     booleam wasEmpty = isEmpty();
     if(wasEmpty) {
         notifyAll(); // <=== question here

Considering that the chapter was detailing the usage of single
notification and conditional notification, and also that the example
comes from the BoundedBuffer (which is one-in one-out),  I am
wondering what is the benefit of having notifyAll instead of notify.

I feel I am missing something, because indeed BoundedBuffer doesn't
conform to the rules to use notify() instead of notifyAll(), but in
this case when passing from empty to 1-element queue, only one thread
will be able to take().

thanks in advance for hints,

.w( the_mindstorm )p.

More information about the Concurrency-interest mailing list