有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在等待之前调用java Notify

当我读到wait()notify方法时,我正在读关于多线程的书。我怀疑如果notify()方法在wait()方法之前完成,会发生什么

Wait()方法将再次等待?或者之前的通知对进一步行动有效


共 (1) 个答案

  1. # 1 楼答案

    javadoc for ^{}

    Causes the current thread to wait until another thread invokes the java.lang.Object.notify() method or the java.lang.Object.notifyAll() method for this object.

    所以当你打电话的时候

    someObject.wait();
    

    它将等待调用

    someObject.notify(); // or notifyAll()