[concurrency-interest] PriorityBlockingQueue uses a fair lock

Joe Bowbeer joe.bowbeer at gmail.com
Wed May 5 20:46:42 EDT 2010


Switching the lock type was suggested in 2006, but after lengthy discussion
it was decided that adding a non-fair option would be safer.

Doug wrote:

We can't just switch in nonfair lock mainly because people

on uniprocessors may unknowingly rely on it to keep producer-consumer

chains more balanced. I know that this does arise because someone

once asked me why their program using ArrayBlockingQueue was causing

memory retention on uniprocessors but not multiprocessors. I told

him to use fair mode, which was an effective bandaid.  (I hate using

fairness for such purposes, but it was better than him having to

redesign program.)



On Wed, May 5, 2010 at 5:14 PM, David Holmes wrote:

> Hi Martin,
>
> > A colleague noticed that PriorityBlockingQueue's
> > internal lock is a fair ReentrantLock,
> > when a non-fair lock would be much faster
> > and usually "fair" enough.  Is there some history here?
>
> Yes but even when it was discussed by the EG on January 11 2006 the history
> had been lost somewhat.
>
> > Should we add a non-fair option for constructing PBQ?
>
> Yes. This addition was deemed too-late for Java 6 inclusion, but should
> have
> been listed for Java 7.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20100505/73e92f72/attachment.html>


More information about the Concurrency-interest mailing list