Java Thread Programming 1.8.2-Inter-thread Commu

Source: Internet
Author: User

Missed Notification
A missed notification occurs when threadB tries to handle y threadA, but threadA is not yet waiting for the notification. in a multithreaded environment like Java, you don't have much control over which thread runs and for how long. this uncertainty can lead to a situation in which most of the time an application is run, threadA is waiting before threadB does the notification. but occasionally, threadB does the notification before threadA is waiting. this missed notification scenario can be quite dangerous.
Missed Notification indicates that thread B tries to notify thread A, but Thread A is not waiting for the Notification. This is not impossible. In a multi-threaded environment, we cannot control which thread to execute and how long it takes to execute. This uncertainty may lead to a notification before a thread waits. This is a very dangerous situation. This happens in the following program:
/*
* Created on 2005-7-14
 *
* Java Thread Programming-Paul Hyde
* Copyright? 1999 Sams Publishing
* Jonathan Q. Bo study notes
 *
*/
Package org. tju. msnrl. jonathan. thread. chapter8;
/**
* @ Author Jonathan Q. Bo from TJU MSNRL
 *
* Email: jonathan.q.bo@gmail.com
* Blog: blog.111cn.net/jonathan_q_bo
* Blog.yesky.net/jonathanundersun
 *
* Enjoy Life with Sun!
 *
*/
Public class MissedNotify {
  
Private Object proceedLock;
  
Public MissedNotify (){
      
ProceedLock = new Object ();
    }
  
Public void waitProceed () throws InterruptedException {
Print ("in waitProceed ()-begin ");
      
Synchronized (proceedLock ){
Print ("begin synchronized wait ...");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.