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");