<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語言

    主站蜘蛛池模板: 精品国产污污免费网站入口在线| 亚洲AⅤ男人的天堂在线观看| www在线观看免费视频| 国产又粗又长又硬免费视频| 亚洲人成人无码.www石榴| 国产v精品成人免费视频400条| 99久久亚洲精品无码毛片| 国产亚洲免费的视频看| 日韩精品一区二区亚洲AV观看| 精品无码无人网站免费视频| 亚洲一区二区免费视频| 免费一本色道久久一区| 亚洲av成本人无码网站| 亚洲精品无码久久不卡| 手机看片国产免费永久| 亚洲伊人tv综合网色| a毛片基地免费全部视频| 亚洲AV香蕉一区区二区三区| 亚洲精品尤物yw在线影院| 91在线视频免费观看| 亚洲高清视频在线播放| 成年午夜视频免费观看视频| 国产精品自拍亚洲| 亚洲国产另类久久久精品黑人 | 亚洲国产欧美日韩精品一区二区三区 | 亚洲色偷偷偷网站色偷一区| 男人的好看免费观看在线视频| 日韩国产欧美亚洲v片| 2048亚洲精品国产| 69pao强力打造免费高清| 亚洲国产成人AV在线播放| 亚洲中文字幕在线第六区| 在线观看www日本免费网站| 亚洲Av永久无码精品黑人| 国产亚洲成归v人片在线观看| 99久久免费观看| mm1313亚洲国产精品无码试看| 亚洲精品美女久久久久99| 两个人的视频高清在线观看免费| 色老头综合免费视频| 亚洲影院在线观看|