`
hanhg
  • 浏览: 133296 次
  • 性别: Icon_minigender_1
  • 来自: 沈阳
社区版块
存档分类
最新评论

What the different is between notify and notifyall

阅读更多
the difference between notify and notifyAll
1 notify is wake the thread which invoke the wait-method
2 notifyAll is wake all the threads waiting for the lock released
3 why can form the thread invoking the wait-method and threads waiting for the lock released?
   we know, if a synchronized method is invoked, all the other synchronized methods belong to the object can not be invoked, so the invoking threads must be blocked, and waiting the method can be invoke, so they all waite for the lock released in the list of waiting queue.
   a synchronized class is the same;
   when the notify method occurs, the waiting one who invoked wait() be wake;
   when the notifyAll method occurs, the waiting queue choose the most prior one to wake, can be the one invoking wait(), also can be the ones waiting the lock released;
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics