Thread.sleep(1000); //可以导致遗漏通知
只是sleep一次而已,1000后,执行mn.waitToProceed();
不会遗漏的

解决方案 »

  1.   

    main()函数里final MissedNotify mn = new MissedNotify();应该是MissedNotifyFix吧!!
    我运行了一下,没有例外抛出呀!!
    这是运行结果:
    D:\>java MissedNotifyFix
    main:in MissedNotify()
    threadB:in proceed()-entered
    //////////////////////////
    threadB:true
    threadB:in proceed()-about to notifyAll()
    threadB:in proceed()-back from notifyAll()
    threadB:in proceed()-leaving
    threadA:in waitToProceed()-entered
    threadA:in waitToProceed()-entered sync block
    threadA:in waitToProceed()-leaving sync block
    threadA:in waitToProceed()-leaving
    main:about to invoke interrupt() on threadA
      

  2.   

    没有抛出啊
    只是编译没通过
    我把49行 //final MissedNotify mn = new MissedNotify();
    改为 final MissedNotifyFix mn = new MissedNotifyFix();
    编译后运行结果为
    main:in MissedNotify()
    threadB:in proceed()-entered
    //////////////////////////
    threadB:true
    threadB:in proceed()-about to notifyAll()
    threadB:in proceed()-back from notifyAll()
    threadB:in proceed()-leaving
    threadA:in waitToProceed()-entered
    threadA:in waitToProceed()-entered sync block
    threadA:in waitToProceed()-leaving sync block
    threadA:in waitToProceed()-leaving
    main:about to invoke interrupt() on threadA