[concurrency-interest] Custom Lock

Doug Lea dl@cs.oswego.edu
Wed, 7 Jan 2004 20:44:00 -0500


Building a priority-inversion lock using AbstractQueuedSynchronizer
looks possible but not easy. AQS builds-in the use of a FIFO queue,
not a priority queue. If you have a small number of priorities (which
you do if you are using 1-10 java.lang.Thread priorities), one way to
go about it would be to use an array of instances of an AQS
specialized to deal with each level.  Then you would need to build
something on top of this that manages the priority inversion, and
releases from the right queue upon lock release.

I'm not sure this design is worth pursuing though.  Beware that
priority settings are only rough scheduling hints in Java. On many
systems, setting priorities has practically no impact on scheduling, so
there is little sense in building a complicated lock mechanism here.

BTW, after testing it out with various example usages, we recently
changed some method names in AbstractQueuedSynchronizer and added a
few others to make it a bit more straightforward to use.

-Doug