Reputation: 81
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 ?
Upvotes: 2
Views: 2818
Reputation: 2759
I believe ReentrantReadWriteLock (Java 5+) is just made for your requirements.
Upvotes: 1