如果没有调用notify(),等待线程会发生什么? [英] What happens to waiting thread if notify() is not called?

查看:203
本文介绍了如果没有调用notify(),等待线程会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果未调用notify(),等待线程会发生什么?这是虚假的唤醒吗?

What happens to waiting thread if notify() is not called? Is this spurious wakeup?

推荐答案

如果等待 线程 notify() notifyAll(),c $ c>未通知所述线程正在等待的对象,然后可能发生以下任何一种情况:

If a waiting Thread is not notified by calling notify() or notifyAll() on the object the said thread is waiting on, then any one of the following may happen:


  • 线程继续在对象的等待池中等待

  • 线程变为 runnable 如果指定超时且时间已过去

  • 线程获取中断并成为 runnable 再次

  • 主题醒来时没有原因即...它既没有通知也没有中断

  • the Thread keeps waiting in the object's wait pool
  • the Thread becomes runnable if a timeout was specified and the time elapses
  • the Thread gets interrupted and becomes runnable again
  • the Thread wakes up for no reason at all i.e. it was neither notified nor interrupted

最后一个案例被称为虚假唤醒并且是唤醒后的原因之一线程应始终检查它等待的条件是否为真或不。如果没有, Thread 应该调用并再次 wait()

The last case is known as a spurious wake-up and is one of the reasons why upon wake-up a Thread should always check whether the condition it was waiting for is true or not. If not, the Thread should call and go wait() again.

这篇关于如果没有调用notify(),等待线程会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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