大家都在看
java线程中notify什么意思
最佳答案
每个对象都有一个监视器,wait和notify都必须针对同一个监视器,
Student中notify是通知在this上等待的线程,wait是让出this的监视器,等待其它线程在this上的通知
Teacher中wait是等待其它线程在this上的通知,而且也没有通知其它线程,与Student不对应
大致代码如下:
Student:
synchronized(Test.class) {
while(true) {
//do....
Test.class.notify();
Test.class.wait();
}
}
Teacher:
synchronized(Test.class) {
Test.class.wiat();
//do....
Test.class.nofity();
}
声明:知趣百科所有作品均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请在页面底部查找“联系我们”的链接,并通过该渠道与我们取得联系以便进一步处理。