<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 閱讀(3601) 評論(0)  編輯  收藏 所屬分類: JavaSE語言

    主站蜘蛛池模板: 一级毛片试看60分钟免费播放| 99亚偷拍自图区亚洲| 国产精品亚洲精品日韩电影| 国产精品视频免费一区二区| 亚洲啪啪免费视频| 日韩精品免费一级视频| 亚洲男人天堂影院| 可以免费看黄的网站| 亚洲一级特黄特黄的大片| 欧美好看的免费电影在线观看 | 久久亚洲国产成人影院网站| 日韩色日韩视频亚洲网站| 亚洲成a人片在线播放| 一级毛片免费观看不收费| 亚洲区小说区图片区QVOD| 四虎影视成人永久免费观看视频 | 亚洲欧洲高清有无| 无码中文在线二区免费| 色综合久久精品亚洲国产| 亚洲精品成人a在线观看| 中文在线免费观看| 亚洲电影唐人社一区二区| 在线a级毛片免费视频| 特级毛片aaaa级毛片免费| 亚洲精品无码永久中文字幕| 一级毛片不卡片免费观看| 亚洲最大无码中文字幕| 亚洲精品456播放| 18以下岁毛片在免费播放| 亚洲精品无码久久久久A片苍井空| 国产伦精品一区二区三区免费迷| 91av免费在线视频| 亚洲国产精品白丝在线观看| 又黄又爽一线毛片免费观看 | 亚洲精品人成网线在线播放va| 亚洲AV中文无码乱人伦| 日本一道本不卡免费| 亚洲精品无码中文久久字幕| 中文字幕日韩亚洲| 美女视频黄是免费的网址| 一级毛片a免费播放王色|