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

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

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

    gembin

    OSGi, Eclipse Equinox, ECF, Virgo, Gemini, Apache Felix, Karaf, Aires, Camel, Eclipse RCP

    HBase, Hadoop, ZooKeeper, Cassandra

    Flex4, AS3, Swiz framework, GraniteDS, BlazeDS etc.

    There is nothing that software can't fix. Unfortunately, there is also nothing that software can't completely fuck up. That gap is called talent.

    About Me

     

    Java: wait(), notify(), notifyAll()

    In Java, any object can act as a monitor - that's an entity with a single lock, an entry queue, and a waiting queue. An object's method without qualifed by the keyword synchronized  can be invoked by any number of  threads at any time, the lock is ignored. The synchronized method of an object, one and only one thread, who owns the lock of that object, can be permitted to run that method at any time;i.e. a synchronized method is mutually exclusive . If, at the time of invocation, another thread owns the lock, then the calling thread will be put in the Blocked state and is added to the entry queue.

    The wait(), notify(), and notifyAll() methods should be called for an object only when the current thread has already locked the object's lock. This point sometimes goes unnoticed because programmers are used to calling these methods from within synchronized methods or blocks. Otherwise, you will get "java.lang.IllegalMonitorStateException: current thread not owner" at runtime.

    When a thread running in a synchronized method of an object is calling the wait() method of the same object, that thread releases the lock of the object and is added to that object's waiting queue. As long as it's there, it sits idle. Note also that wait() forces the thread to release its lock. This means that it must own the lock of an object before calling the wait() method of that (same) object. Hence the thread must be in one of the object's synchronized methods or synchronized block before calling wait().

    When a thread invokes an object's notify() or notifyAll() method, one (an arbitrary thread) or all of the threads in its waiting queue are removed from the waiting queue to the entry queue. They then actively contend for the object's lock, and the one that gets the lock goes on to execute. If no threads are waiting in the waiting queue, then notify() and notifyAll() have no effect. Before calling the notify() or notifyAll() method of an object, a thread must own the lock of the object. Hence it must be in one of the object's  synchronized methods or synchronized block.

    A thread in the waiting queue of an object can run again only when some other thread calls the notify() (or the notifyAll) method of the same object.

    The reason to call wait() is that the thread does not want to execute a block of code until a particular state to be achieved. It wants to wait until a particular state to be achieved. The reason to call notify() or notifyAll() method is that the thread will signal others that "a particular state has been achieved". The state is a communication channel between threads and it must be shared mutable state.

    For example, one thread read data from a buffer and one thread write data into buffer. The reading data thread needs to wait until the writing data thread completly write a block data into the buffer. The wirting data thread needs to wait until the reading data thread completly read the data from the buffer. If wait(), notify(), and notifyAll() methods can be called by a ordinary method , the reading thread calls wait() and the thread is being added to waiting queue . At just the same moment, the writing thread calls notify() to signal the condition changes. The reading thread misses the change and waits forever. Hence, they must be called inside a synchronized method or block which is mutually exclusive.

    posted on 2010-06-29 10:28 gembin 閱讀(881) 評論(0)  編輯  收藏 所屬分類: JavaSE

    導航

    統計

    常用鏈接

    留言簿(6)

    隨筆分類(440)

    隨筆檔案(378)

    文章檔案(6)

    新聞檔案(1)

    相冊

    收藏夾(9)

    Adobe

    Android

    AS3

    Blog-Links

    Build

    Design Pattern

    Eclipse

    Favorite Links

    Flickr

    Game Dev

    HBase

    Identity Management

    IT resources

    JEE

    Language

    OpenID

    OSGi

    SOA

    Version Control

    最新隨筆

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    free counters
    主站蜘蛛池模板: 久久99久久成人免费播放| 中文字幕人成无码免费视频| 成人毛片免费网站| 亚洲欧美日韩自偷自拍| 成年女性特黄午夜视频免费看| 精品国产成人亚洲午夜福利| 免费a级毛片无码a∨蜜芽试看| 亚洲沟沟美女亚洲沟沟| 99视频全部免费精品全部四虎| 中文字幕在线观看亚洲视频| 97无码免费人妻超级碰碰碰碰 | 免费一级毛片清高播放| 黄色三级三级免费看| 亚洲男人天堂2020| 色www永久免费网站| 亚洲无删减国产精品一区| 成人免费的性色视频| 亚洲熟妇无码八V在线播放| 国产免费无遮挡精品视频| 美女被免费网站91色| 精品亚洲国产成AV人片传媒| 一个人免费观看在线视频www| 亚洲av成人无码网站…| AV在线亚洲男人的天堂| 亚洲视频在线免费观看| 亚洲AV综合色区无码二区偷拍| 国产又大又长又粗又硬的免费视频 | 亚洲狠狠婷婷综合久久久久| 久久久国产精品无码免费专区| 91亚洲国产成人久久精品网址| 永久免费看mv网站入口| 中文字幕免费播放| 亚洲精品在线播放视频| 国产成人aaa在线视频免费观看 | 波多野结衣免费一区视频| 亚洲另类小说图片| 亚洲精品麻豆av| 很黄很色很刺激的视频免费| 日日狠狠久久偷偷色综合免费 | 国产精品免费观看| 一级中文字幕免费乱码专区 |