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.
//喚醒正在此對(duì)象的監(jiān)視器上等待的單個(gè)線程旋廷。
如果有任何線程在此對(duì)象上等待赊舶,則選擇其中一個(gè)喚醒抑堡。
該選擇是任意的站玄,并且可以根據(jù)實(shí)現(xiàn)情況進(jìn)行選擇。
線程通過調(diào)用其中一個(gè)wait方法在對(duì)象的監(jiān)視器上等待
* <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.
//在當(dāng)前線程放棄對(duì)該對(duì)象的鎖定之前包券,喚醒的線程將無法繼續(xù)纫谅。
喚醒的線程將以通常的方式與可能正在主動(dòng)競(jìng)爭(zhēng)以在此對(duì)象上
進(jìn)行同步的任何其他線程競(jìng)爭(zhēng)。 例如溅固,喚醒的線程
在成為鎖定該對(duì)象的下一個(gè)線程時(shí)沒有任何可靠的特權(quán)或劣勢(shì)付秕。
* <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:
此方法只能由作為該對(duì)象的監(jiān)視器的所有者的線程調(diào)用。
線程可以通過以下三種方式之一成為對(duì)象監(jiān)視器的所有者:
* <ul>
* <li>By executing a synchronized instance method of that object.
通過執(zhí)行該對(duì)象的同步實(shí)例方法侍郭。
* <li>By executing the body of a {@code synchronized} statement
* that synchronizes on the object.
通過執(zhí)行在對(duì)象上同步的同步語句的主體询吴。
* <li>For objects of type {@code Class,} by executing a
* synchronized static method of that class.
對(duì)于類類型的對(duì)象掠河,請(qǐng)執(zhí)行該類的同步靜態(tài)方法。
* </ul>
* <p>
* Only one thread at a time can own an object's monitor.
一次只能有一個(gè)線程擁有對(duì)象的監(jiān)視器猛计。
*
* @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.
//喚醒正在此對(duì)象的監(jiān)視器上等待的所有線程唠摹。 線程通過調(diào)用其中一個(gè)wait方法在對(duì)象的監(jiān)視器上等待。
* <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.
//在當(dāng)前線程放棄對(duì)該對(duì)象的鎖定之前奉瘤,喚醒的線程將無法繼續(xù)勾拉。
喚醒的線程將以通常的方式與任何其他可能正在主動(dòng)競(jìng)爭(zhēng)以在此對(duì)象上進(jìn)行同步的線程競(jìng)爭(zhēng)。
例如盗温,被喚醒的線程在成為鎖定該對(duì)象的下一個(gè)線程時(shí)沒有任何可靠的特權(quán)或劣勢(shì)藕赞。
* <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.
//此方法只能由作為該對(duì)象的監(jiān)視器的所有者的線程調(diào)用。
有關(guān)線程可以成為監(jiān)視器所有者的方式的描述卖局,請(qǐng)參見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();