简体   繁体   English

可运行的调用notifyall来唤醒自己-Java

[英]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的结尾-我想唤醒YX具有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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM