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

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

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

    cuiyi's blog(崔毅 crazycy)

    記錄點滴 鑒往事之得失 以資于發(fā)展
    數(shù)據(jù)加載中……

    java基礎(chǔ)(五):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方法必須在與之對應(yīng)的對象的同步塊里調(diào)用)
    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 閱讀(3601) 評論(0)  編輯  收藏 所屬分類: JavaSE語言

    主站蜘蛛池模板: 国产免费拔擦拔擦8X高清在线人| 亚洲精品乱码久久久久久蜜桃图片 | 亚洲乱码一二三四五六区| a毛片免费播放全部完整| 国产亚洲精品线观看动态图| 成人免费夜片在线观看| 亚洲av无码不卡私人影院| 色吊丝免费观看网站| 亚洲精品黄色视频在线观看免费资源 | sihu国产精品永久免费| 在线播放亚洲第一字幕| 91在线免费观看| 亚洲男人天堂av| 久久久免费精品re6| 亚洲国产av高清无码| 全免费一级午夜毛片| 亚洲av午夜电影在线观看| 亚洲成人一区二区| 国产又黄又爽胸又大免费视频| 亚洲精品少妇30p| 91成人在线免费观看| 亚洲国产日韩视频观看| 全黄性性激高免费视频| 久久er国产精品免费观看8| 亚洲第一福利视频| 无人影院手机版在线观看免费| 亚洲av日韩av永久在线观看| 亚洲高清无码综合性爱视频| 中文字幕无码日韩专区免费 | 好爽好紧好大的免费视频国产| 免费观看亚洲人成网站| 亚洲精品午夜无码电影网| h视频在线免费看| 国产午夜亚洲精品不卡| 精品亚洲永久免费精品| 性短视频在线观看免费不卡流畅| 日韩成人精品日本亚洲| 国产亚洲一区二区精品| 成全高清视频免费观看| 一个人看www免费高清字幕| 666精品国产精品亚洲|