简体   繁体   English

具有读/写锁定的信号灯

[英]Semaphore with Read/Write Lock

If a thread has lock on any object, can read methods still work ? 如果线程在任何对象上都有锁,则读取方法是否仍然有效?

If I have object with various 'get' methods than can I use the object to do print outs while some other thread has lock on it ? 如果我的对象具有各种“获取”方法,那么当其他线程对其进行锁定时,我可以使用该对象进行打印输出吗? I am working on project where object has various properties, which I need to print it out periodically. 我正在研究对象具有各种属性的项目,我需要定期将其打印出来。 However, there are other threads running which may gain lock to write those properties. 但是,还有其他正在运行的线程可能获得锁定以写入那些属性。 I am using Semaphore for synchronization. 我正在使用信号量进行同步。 Also, I will be doing more reading than writing. 另外,我将做的比阅读更多。 What is the best approach to tackle these situation ? 解决这些情况的最佳方法是什么?

我相信ReentrantReadWriteLock (Java 5+)正是根据您的要求而设计的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM