Java Thread Programming 1.8.2 - Inter-thread Commu

來源:互聯網
上載者:User

Missed Notification
A missed notification occurs when threadB tries to notify 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指:線程B試圖通知線程A,但線程A並沒有在等待通知。這並不是不可能出現的。在多線程環境中,我們不能控制哪個線程執行,執行多長時間,這種不確定有可能導致在一個線程等待之前就先行通知,這是一種很危險的情況。如下程式會出現這種情況:
/*
 * Created on 2005-7-14
 *
 * Java Thread Programming - Paul Hyde
 * Copyright ? 1999 Sams Publishing
 * Jonathan Q. Bo 學習筆記
 *
 */
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 ...");

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.