<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    cuiyi's blog(崔毅 crazycy)

    記錄點滴 鑒往事之得失 以資于發展
    數據加載中……

    java基礎(五):Java同步機制之notify vs notifyAll

    use the wait-and-notify mechanism to deal with synchronized accessing a resource

    wait-and-notify mechanism
    1 wait & notify can never be out of synchronized block of the releated-object (wait和notify方法必須在與之對應的對象的同步塊里調用)
    2 wait can release & get the lock automatically

    the difference between notify and notifyAll
    1 notify is wake the thread which invoke the wait-method
    2 notifyAll is wake all the thread waiting for the lock released
    3 why can form the thread invoking the wait-method and threads waiting for the lock released?
    ?? we know, if a synchronized method is invoked, all the other synchronized methods belong to the object can not be invoked, so the invoking threads must be blocked, and waiting the method can be invoke, so they all waite for the?lock released in the list of waiting queue.
    ?? a?synchronized class is the same;
    ?? when the notify method occurs, the waiting one who invoked wait() be wake;
    ???when the notifyAll method occurs, the waiting queue choose the most?prior one to wake, can be the one invoking wait(), also can be the ones waiting the lock released;


    what we should be care?
    if?one waiting thread is?waked, its waiting condition may not be?satisfied.?and?in the right way, it should wait continuely.
    how we assure this route??
    --just as follows came?from <Effective Java> and <Practical Java>
    the former: Never invoke wait outside a loop
    ? eg:?
    ?
    1synchronized(obj)?{
    2????while(<condition?does?not?hold>)?{
    3???????wait();?
    4????????//?Perform?action?appropriate?to?condition
    5????? ?}

    6?}

    the later: Use spin locks to deal with wait and notifyAll

    posted on 2007-01-24 20:14 crazycy 閱讀(3591) 評論(0)  編輯  收藏 所屬分類: JavaSE語言

    主站蜘蛛池模板: 偷自拍亚洲视频在线观看99| 亚洲中文无码卡通动漫野外| 一级毛片免费在线| 国产精品美女自在线观看免费| 亚洲人成未满十八禁网站| 最近中文字幕免费mv视频7| 亚洲日韩一区二区三区| 国产免费观看a大片的网站| 直接进入免费看黄的网站| 亚洲а∨天堂久久精品| 国产福利在线观看永久免费| 国产亚洲精久久久久久无码AV| 免费看无码特级毛片| 亚洲成a人片77777老司机| 在线观看www日本免费网站| 亚洲一级毛片中文字幕| 免费看美女被靠到爽的视频| 色五月五月丁香亚洲综合网| 亚洲日韩中文字幕日韩在线 | 亚洲爆乳无码一区二区三区| 国产成人免费ā片在线观看老同学 | 日本中文一区二区三区亚洲| 一个人看的www免费高清 | 亚洲国产美女精品久久久久| 午夜免费福利影院| 特级毛片A级毛片100免费播放| 亚洲人成在线播放网站| 99视频有精品视频免费观看| 在线a亚洲老鸭窝天堂av高清| 免费中文字幕不卡视频| 国产精品区免费视频| 亚洲日本乱码卡2卡3卡新区| 中文字幕亚洲天堂| 亚州免费一级毛片| 香蕉视频免费在线播放| 亚洲成色在线影院| 国产真实伦在线视频免费观看| 两个人看的www高清免费观看| ww亚洲ww在线观看国产| 亚洲精品麻豆av| 100000免费啪啪18免进|