[英]runnable calls notifyall to wake itself - java
I have a class that implements Callable
, X
, and a class that implements Runnable
, Y
. 我有一个实现
Callable
X
的类和一个实现Runnable
Y
。
Y
has a collection of X
's , and when one of X
's ends I want to wake Y
, X
has Y
as a private field, can I just use Y.notifyAll()
to wake it? Y
有集合X
的,当一个X
的结尾-我想唤醒Y
, X
具有Y
作为私人领域,可我只是用Y.notifyAll()
来唤醒它?
If you have Y
as a private member of X
, you can call a method in Y
directly. 如果您拥有
Y
作为X
的私有成员,则可以直接在Y
调用方法。
Y.notifyAll()
will notify all threads that already called wait()
on the same instance of Y
. Y.notifyAll()
将在Y
的相同实例上通知所有已调用wait()
线程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.