Reputation: 15834
Is there any Lock in Java that would allow me to do this?
Upvotes: 2
Views: 213
Reputation: 7413
It sounds like there is no circumstance under which reads cannot occur. Do you really need a read lock? If not, then you should just be able to use a Semaphore with 1 permit to protect the write permission. If you still want to track how many reads are happening without the ability to prevent any, you can always count how many reads are in flight with an AtomicInteger.
Upvotes: 1