I'm looking for en efficient system to have a series of read/write locks organized hierarchically to manage access to hierarchically organized resources. If a subtree is locked for write, then no other lock should be able to be obtained in the whole subtree until it is released; similarly, a write lock in a subtree should prevent locking in a parent.
Here are the ideas I was contemplating:
Use the Apache Commons Transaction. Unforunately, the project hasn't been updated since March 2008 and has unofficially been terminated. Some API docs seemed to indicate that the version to come (1.3 or 2.0) would include some kind of hierarchical locking, but the sources are nowhere to be found and it seems we can't access their SVN repository any more.
Use a series of
ReentrantReadWriteLock
s, which I would organize hierarchically. I'm no concurrency expert, and I'm a bit afraid to do that on my own. Preliminary thoughts seemed to indicate that even before I can try to lock a subtree, I'd have to use an outer lock on the whole structure managing theReentrantReadWriteLock
s itself — so that even for releasing a lock I'd have to use the outer lock…Use classes from
java.util.concurrent
andjava.util.concurrent.atomic
to implement my hierarchical lock in a more efficient way than I could do with a series ofReentrantReadWriteLock
s.
I'm ready to go down that last road, but I was surprised not to find any exiting library that would solve this problem better. So:
- Have I missed some obvious solution?
- Or is this problem just especially hard to solve properly?