[英]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? Java中是否有任何锁可以让我做到这一点?
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.
如果没有,那么您应该只能使用具有1个许可的信号量来保护写许可权。 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 .
如果您仍想跟踪发生了多少次读取而又无法阻止任何读取,则可以始终使用AtomicInteger计数正在运行的读取数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.