什么是Java的等效ManualResetEvent的呢? [英] What is java's equivalent of ManualResetEvent?

查看:668
本文介绍了什么是Java的等效ManualResetEvent的呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是Java中的等价物<一href="http://msdn.microsoft.com/en-us/library/system.threading.manualresetevent.aspx">ManualResetEvent?

What is java's equivalent of ManualResetEvent?

推荐答案

最近我所知道的是的Semaphore 。只需将其与许可证的1计数,并AQUIRE /释放将是pretty的一样一样的,你知道从什么的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的呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆