user219882
user219882

Reputation: 15834

The best Lock for concurrency: one WRITE and infinite number of READ

Is there any Lock in Java that would allow me to do this?

Upvotes: 2

Views: 213

Answers (1)

sigpwned
sigpwned

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

Related Questions