如何知道哪个线程受到notify()或notifyAll()影响 - Java
有没有办法知道哪个活动实体线程正在受到notify()
或notifyAll()
的影响,这些线程是从被动实体互斥体内部调用。
Is there a way to know which Active Entity thread(s) is/are being affected by a notify()
or notifyAll()
which are called from inside of a Passive Entity Mutex.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无法从调用
notify()
的线程得知哪个线程被唤醒。此外,无法从唤醒的线程知道哪个线程唤醒了它们。
事情就是这样。
There is no way to know from the thread that makes the call to
notify()
which threads are woken up.Also, there is no way to know from the woken up thread which thread woke them up.
It's just the way it is.
如果您需要知道这些信息,您可以创建一个记录这些信息的数据结构。但是,您很少需要知道这一点,因此它不会自动为您执行此操作。
If you need to know this information, you can create a data structure which records this information. However, you rarely need to know this so it doesn't do this for you automatically.