<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 閱讀(875) 評論(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
    主站蜘蛛池模板: 亚洲欧美日韩中文无线码| 久久国产成人精品国产成人亚洲 | 国产免费黄色无码视频| 午夜免费福利影院| 亚洲一区二区三区高清在线观看| 亚洲免费视频网址| 亚洲国产视频网站| 国产福利在线免费| 亚洲色大成WWW亚洲女子| 岛国大片免费在线观看| 亚洲欧洲AV无码专区| 日本人的色道www免费一区| 亚洲av中文无码字幕色不卡| 国产精品二区三区免费播放心| 日韩亚洲翔田千里在线| 免费人成视频x8x8入口| 91精品全国免费观看青青| 亚洲AV日韩AV永久无码久久| 99久久综合精品免费| 77777亚洲午夜久久多喷| 日韩一区二区三区免费体验| 日日狠狠久久偷偷色综合免费 | 亚洲精华国产精华精华液网站| 国产成人免费福利网站| 一级做a毛片免费视频| 久久精品国产亚洲一区二区| 最近免费中文字幕大全免费| 一本色道久久88亚洲精品综合| 国产一级淫片a免费播放口之| 国产大片免费天天看| 久久久国产精品亚洲一区| 最近最新的免费中文字幕 | 中国一级特黄高清免费的大片中国一级黄色片 | 在线观看免费人成视频色9| 亚洲国产av玩弄放荡人妇| 亚洲人成人网站在线观看| 99久久国产免费中文无字幕| 亚洲国产区男人本色在线观看| 亚洲欧洲一区二区三区| 91精品国产免费入口| 国产成人亚洲午夜电影|