Java - 等待和通知所有 [英] Java - wait and notifyAll

查看:26
本文介绍了Java - 等待和通知所有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你在一个不等待的对象上调用 notifyAll 方法时会发生什么?应该有例外还是正常情况?

What happens when you call notifyAll method on an object that is not waiting? Should there be exception or is it normal situation?

推荐答案

完全正常.您只能通知在一个监视器上等待的所有内容.其他人都没有兴趣.您调用 notifyAll 的对象只是其他人正在等待的监视器.如果没有人在等待,则无需通知任何人

It is completely normal. You can only notify all that waiting on one single monitor. Everybody else is not interested. The object on which you call notifyAll is just the monitor on which others are waiting. If nobody is waiting nobody has to be notified

这篇关于Java - 等待和通知所有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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