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)行選擇。
線程通過(guò)調(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ì)象的鎖定之前,喚醒的線程將無(wú)法繼續(xù)。
喚醒的線程將以通常的方式與可能正在主動(dòng)競(jìng)爭(zhēng)以在此對(duì)象上
進(jìn)行同步的任何其他線程競(jìng)爭(zhēng)。 例如,喚醒的線程
在成為鎖定該對(duì)象的下一個(gè)線程時(shí)沒(méi)有任何可靠的特權(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)用。
線程可以通過(guò)以下三種方式之一成為對(duì)象監(jiān)視器的所有者:
* <ul>
* <li>By executing a synchronized instance method of that object.
通過(guò)執(zhí)行該對(duì)象的同步實(shí)例方法。
* <li>By executing the body of a {@code synchronized} statement
* that synchronizes on the object.
通過(guò)執(zhí)行在對(duì)象上同步的同步語(yǔ)句的主體。
* <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)視器上等待的所有線程。 線程通過(guò)調(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ì)象的鎖定之前,喚醒的線程將無(wú)法繼續(xù)。
喚醒的線程將以通常的方式與任何其他可能正在主動(dòng)競(jìng)爭(zhēng)以在此對(duì)象上進(jìn)行同步的線程競(jìng)爭(zhēng)。
例如,被喚醒的線程在成為鎖定該對(duì)象的下一個(gè)線程時(shí)沒(méi)有任何可靠的特權(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)參見(jiàn)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();
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。