2021
09-30
09-30
ReentrantReadWriteLock不能锁升级的原因总结
为什么ReentrantReadWriteLock不能锁升级在ReentrantReadWriteLock中,锁是不可以升级的,只能降级。也就是如果当前线程持有了ReadLock,那么就不能再获取WriteLock,但是,如果当前线程持有了WriteLock,可以直接获取ReadLock下面用代码尝试一下:Loggerlogger=LoggerFactory.getLogger(this.getClass());ReentrantReadWriteLockreentrantReadWriteLock=newReentrantReadWriteLock();ReentrantReadWriteLock.ReadLockread...
继续阅读 >