什么是 java 的 ManualResetEvent 等价物?

What is java#39;s equivalent of ManualResetEvent?(什么是 java 的 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 等价物?

基础教程推荐