<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

    導航

    統(tǒng)計

    常用鏈接

    留言簿(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
    主站蜘蛛池模板: 亚洲精品无码鲁网中文电影| 女人18一级毛片免费观看| 亚洲精品线路一在线观看 | 无码少妇一区二区浪潮免费| 亚洲日韩激情无码一区| 黄网站在线播放视频免费观看| 国产成人免费手机在线观看视频| 亚洲国产无线乱码在线观看| 免费看美女被靠到爽的视频| 精品国产亚洲第一区二区三区 | 人妻免费一区二区三区最新| 久久亚洲高清综合| 花蝴蝶免费视频在线观看高清版| 亚洲国产精品一区二区第一页 | 免费看污成人午夜网站| 亚洲一级免费毛片| 精品久久久久久久免费人妻 | 中文字幕亚洲天堂| 国产自国产自愉自愉免费24区| 亚洲av无码专区国产乱码在线观看| 日本人成在线视频免费播放| 亚洲免费一级视频| 在线日韩av永久免费观看| 老湿机一区午夜精品免费福利| 亚洲日产韩国一二三四区| 97青青草原国产免费观看| 一本天堂ⅴ无码亚洲道久久| 又黄又大又爽免费视频| 大地资源在线资源免费观看| 亚洲成人高清在线观看| 国产成人免费A在线视频| 中文字幕不卡免费视频| 亚洲国产精品综合久久网各| 国产乱子伦精品免费无码专区| 18禁超污无遮挡无码免费网站| 国产精品亚洲专区在线观看| 亚洲精品NV久久久久久久久久| 亚洲精品视频免费看| 美女被免费网站在线视频免费| 亚洲AV无码国产精品麻豆天美 | 亚洲人成人网站在线观看|