简体   繁体   中英

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+)正是根据您的要求而设计的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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