作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对RentrantReadWriteLock的理解其特点是它允许同时进行多次读取,但只允许一次写入。
当我们尝试获取读锁时 doc州
Acquires the read lock if the write lock is not held by another thread and returns immediately.
If the write lock is held by another thread then the current thread becomes disabled
for thread scheduling purposes and lies dormant until the read lock has been acquired.
这里的held
是什么意思?
或
因为当请求写锁时,如果满足以下条件,则不会授予它:
来自write lock文档:
Acquires the write lock if neither the read nor write lock are held by another
thread and returns immediately, setting the write lock hold count to one.
...
If the lock is held by another thread then the current thread becomes
disabled for thread scheduling purposes and lies dormant until the write lock has
been acquired, at which time the write lock hold count is set to one.
因此,当线程在请求写入锁后等待写入锁时,我只想了解读取锁调用的后续行为。他们是否会让写锁请求等待更长时间?
最佳答案
在此上下文中
持有表示已请求并提供锁定。如果您只是在等待,则不会被视为持有。
当大量线程请求锁定时,ReentrantReadWriteLock
存在已知问题。 Heinz Kabutz 博士制作了一个有趣的 newsletter与他们一起锁饥饿。
据我了解,新的 Java 7 Phaser 已修复其中许多问题。但我还不太熟悉它,无法说是哪种方式。
关于java - 读写RentrantLock,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15721129/
我试图在java中使用ReentrantLock实现生产者消费者 Condition producerlock = lock.newCondition(); Condition con
我是一名优秀的程序员,十分优秀!