What is java#39;s equivalent of ManualResetEvent?(什么是 java 的 ManualResetEvent 等价物?)
问题描述
ManualResetEvent 的 java 等价物是什么?
What is java's equivalent of ManualResetEvent?
推荐答案
我所知道的最接近的是 信号量.只需将其与许可"计数 1 一起使用,获取/释放将与您从 ManualResetEvent
中知道的几乎相同.
The closest I know of is the Semaphore. Just use it with a "permit" count of 1, and aquire/release will be pretty much the same as what you know from the ManualResetEvent
.
初始化为 1 的信号量,并且使用它使其仅具有大多数许可证可用,可以服务作为互斥锁.这是通常称为二进制信号量,因为它只有两个状态:一个许可证可用,或零可用的许可证.用于此方式,二进制信号量有属性(不像许多 Lock实现),锁"可以由线程以外的线程释放所有者(因为信号量没有所有权).这在某些情况下可能很有用专门的上下文,例如死锁恢复.
A semaphore initialized to one, and which is used such that it only has at most one permit available, can serve as a mutual exclusion lock. This is more commonly known as a binary semaphore, because it only has two states: one permit available, or zero permits available. When used in this way, the binary semaphore has the property (unlike many Lock implementations), that the "lock" can be released by a thread other than the owner (as semaphores have no notion of ownership). This can be useful in some specialized contexts, such as deadlock recovery.
这篇关于什么是 java 的 ManualResetEvent 等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:什么是 java 的 ManualResetEvent 等价物?
基础教程推荐
- 如何对 HashSet 进行排序? 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01