線程核心方法-notify忌栅、notifyAll

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();
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市砚偶,隨后出現(xiàn)的幾起案子批销,更是在濱河造成了極大的恐慌,老刑警劉巖染坯,帶你破解...
    沈念sama閱讀 218,755評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件均芽,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡酒请,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門鸣个,熙熙樓的掌柜王于貴愁眉苦臉地迎上來羞反,“玉大人,你說我怎么就攤上這事囤萤≈绱埃” “怎么了?”我有些...
    開封第一講書人閱讀 165,138評(píng)論 0 355
  • 文/不壞的土叔 我叫張陵涛舍,是天一觀的道長(zhǎng)澄惊。 經(jīng)常有香客問我,道長(zhǎng)富雅,這世上最難降的妖魔是什么掸驱? 我笑而不...
    開封第一講書人閱讀 58,791評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮没佑,結(jié)果婚禮上毕贼,老公的妹妹穿的比我還像新娘。我一直安慰自己蛤奢,他們只是感情好鬼癣,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,794評(píng)論 6 392
  • 文/花漫 我一把揭開白布陶贼。 她就那樣靜靜地躺著,像睡著了一般待秃。 火紅的嫁衣襯著肌膚如雪拜秧。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,631評(píng)論 1 305
  • 那天章郁,我揣著相機(jī)與錄音枉氮,去河邊找鬼。 笑死驱犹,一個(gè)胖子當(dāng)著我的面吹牛嘲恍,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播雄驹,決...
    沈念sama閱讀 40,362評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼佃牛,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了医舆?” 一聲冷哼從身側(cè)響起俘侠,我...
    開封第一講書人閱讀 39,264評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎蔬将,沒想到半個(gè)月后爷速,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,724評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡霞怀,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,900評(píng)論 3 336
  • 正文 我和宋清朗相戀三年惫东,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片毙石。...
    茶點(diǎn)故事閱讀 40,040評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡噪舀,死狀恐怖拯辙,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤少欺,帶...
    沈念sama閱讀 35,742評(píng)論 5 346
  • 正文 年R本政府宣布刃泡,位于F島的核電站虑省,受9級(jí)特大地震影響忧饭,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜鳞骤,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,364評(píng)論 3 330
  • 文/蒙蒙 一窒百、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧豫尽,春花似錦贝咙、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽窟她。三九已至,卻和暖如春蔼水,著一層夾襖步出監(jiān)牢的瞬間震糖,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評(píng)論 1 270
  • 我被黑心中介騙來泰國(guó)打工趴腋, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留吊说,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,247評(píng)論 3 371
  • 正文 我出身青樓优炬,卻偏偏與公主長(zhǎng)得像颁井,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子蠢护,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,979評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容