美文网首页java多线程
线程核心方法-notify、notifyAll

线程核心方法-notify、notifyAll

作者: 余生爱静 | 来源:发表于2021-05-01 00:27 被阅读0次

notify源码

 /**
     * Wakes up a single thread that is waiting on this object's
     * monitor. If any threads are waiting on this object, one of them
     * is chosen to be awakened. The choice is arbitrary and occurs at
     * the discretion of the implementation. A thread waits on an object's
     * monitor by calling one of the {@code wait} methods.
     //唤醒正在此对象的监视器上等待的单个线程。 
      如果有任何线程在此对象上等待,则选择其中一个唤醒。
     该选择是任意的,并且可以根据实现情况进行选择。 
     线程通过调用其中一个wait方法在对象的监视器上等待
     * <p>
     * The awakened thread will not be able to proceed until the current
     * thread relinquishes the lock on this object. The awakened thread will
     * compete in the usual manner with any other threads that might be
     * actively competing to synchronize on this object; for example, the
     * awakened thread enjoys no reliable privilege or disadvantage in being
     * the next thread to lock this object.
     //在当前线程放弃对该对象的锁定之前,唤醒的线程将无法继续。
      唤醒的线程将以通常的方式与可能正在主动竞争以在此对象上
     进行同步的任何其他线程竞争。 例如,唤醒的线程
     在成为锁定该对象的下一个线程时没有任何可靠的特权或劣势。
     * <p>
     * This method should only be called by a thread that is the owner
     * of this object's monitor. A thread becomes the owner of the
     * object's monitor in one of three ways:
     此方法只能由作为该对象的监视器的所有者的线程调用。
     线程可以通过以下三种方式之一成为对象监视器的所有者:
     * <ul>
     * <li>By executing a synchronized instance method of that object.
             通过执行该对象的同步实例方法。
     * <li>By executing the body of a {@code synchronized} statement
     *     that synchronizes on the object.
           通过执行在对象上同步的同步语句的主体。
     * <li>For objects of type {@code Class,} by executing a
     *     synchronized static method of that class.
           对于类类型的对象,请执行该类的同步静态方法。
     * </ul>
     * <p>
     * Only one thread at a time can own an object's monitor.
        一次只能有一个线程拥有对象的监视器。
     *
     * @throws  IllegalMonitorStateException  if the current thread is not
     *               the owner of this object's monitor.
     * @see        java.lang.Object#notifyAll()
     * @see        java.lang.Object#wait()
     */
    public final native void notify();

notifyAll源码

 /**
     * Wakes up all threads that are waiting on this object's monitor. A
     * thread waits on an object's monitor by calling one of the
     * {@code wait} methods.
     //唤醒正在此对象的监视器上等待的所有线程。 线程通过调用其中一个wait方法在对象的监视器上等待。
     * <p>
     * The awakened threads will not be able to proceed until the current
     * thread relinquishes the lock on this object. The awakened threads
     * will compete in the usual manner with any other threads that might
     * be actively competing to synchronize on this object; for example,
     * the awakened threads enjoy no reliable privilege or disadvantage in
     * being the next thread to lock this object.
     //在当前线程放弃对该对象的锁定之前,唤醒的线程将无法继续。 
      唤醒的线程将以通常的方式与任何其他可能正在主动竞争以在此对象上进行同步的线程竞争。 
     例如,被唤醒的线程在成为锁定该对象的下一个线程时没有任何可靠的特权或劣势。
     * <p>
     * This method should only be called by a thread that is the owner
     * of this object's monitor. See the {@code notify} method for a
     * description of the ways in which a thread can become the owner of
     * a monitor.
     //此方法只能由作为该对象的监视器的所有者的线程调用。
       有关线程可以成为监视器所有者的方式的描述,请参见notify方法。
     *
     * @throws  IllegalMonitorStateException  if the current thread is not
     *               the owner of this object's monitor.
     * @see        java.lang.Object#notify()
     * @see        java.lang.Object#wait()
     */
    public final native void notifyAll();

相关文章

网友评论

    本文标题:线程核心方法-notify、notifyAll

    本文链接:https://www.haomeiwen.com/subject/babsrltx.html