views:

35

answers:

1

Hello,

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 readLock.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

+1  A: 

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.

Tom Hawtin - tackline