[concurrency-interest] PriorityBlockingQueue put() operation

Joe Bowbeer joe.bowbeer at gmail.com
Sat Nov 7 18:00:44 EST 2009


On Sat, Nov 7, 2009 at 12:01 PM, Michael Spiegel wrote:

> Hi,
>
> I apologize if this question has been answered before of if the answer
> is trivially obvious.  The documentation for
> java.util.concurrent.PriorityBlockingQueue states that the put(E e)
> method will never block, and such claims are not made about the add(E
> e) method.  The method bodies for both methods are identical, ignoring
> the fact that one method returns boolean and the other doesn't return
> a value.  The methods body is an invocation to the offer(E e) method.
> I believe that offer() is a blocking method, since it locks the
> ReentrantLock around the data structure.  So is put() a blocking
> method? I must be missing something obvious.
>
> Thanks!
> --Michael
>


Wikipedia currently makes this distinction:

  "In computer science, non-blocking synchronization ensures that threads
competing for a shared resource do not have their execution indefinitely
postponed by mutual exclusion. A non-blocking algorithm is lock-free if
there is guaranteed system-wide progress; wait-free if there is also
guaranteed per-thread progress."

  http://en.wikipedia.org/wiki/Non-blocking_synchronization

So non-blocking < lock-free < wait-free ?

Consider old (blocking) java.io and the newer asynchronous java.nio.  They
both use locks of some sort, but nio is non-blocking.

Object.wait is typically a good indicator of  blocking.  (As is throws IE.)

--Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20091107/8a1225ca/attachment.html>


More information about the Concurrency-interest mailing list