开发者

Is lock returned by ReentrantReadWriteLock equivalent to it's read and write locks?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜