I have been looking around for the answer to this, but no joy. In Java, is using the lock created by ReentrantReadWriteLock equivalent to getting the read and write locks as returned by readLo开发者_运维知识库ck.lock() and writeLock.lock()? In other words, can I expect the read and write locks associated with the ReentrantReadWriteLock to be requested and held by synchronizing on the ReentrantReadWriteLock?
My gut says "no" since any object can be used for synchronization. I wouldn't think that there would be special behavior for ReentrantReadWriteLock. However, special behavior is the corner case of which I may not be aware.
Thanks, Todd
java.util.concurrent.locks
and lock support in the Java language are completely separate mechanisms.
Some static analysis tools will flag attempting to use synchronized
on a Lock
object.
精彩评论