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

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

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

    敬的世界

    常用鏈接

    統計

    最新評論

    關于 Thread

    We began this section by wondering whether it was preferable to program a task using the Runnable interface or the Thread class. We've seen examples of why you would need each. There's an additional advantage to the Runnable interface, however. With Runnable, Java provides a number of classes that handle threading issues for you. These classes handle thread pooling, task scheduling, or timing issues. If you're going to use such a class, your task must be a Runnable object (or, in some cases, an object that has an embedded Runnable object).

    If you do a thorough program design and Unified Modeling Language (UML) model of your application, the resulting object hierarchy tells you pretty clearly whether your task needs to subclass another class (in which case you must use the Runnable interface) or whether you need to use the methods of the Thread class within your task. But if your object hierarchy is silent on the parent class for your task, or if you do a lot of prototyping or extreme programming, then what? Then the choice is yours: you can use the Runnable interface, which gives you a little more flexibility at the cost of the overhead of keeping track of the thread objects separately, or you can trade that flexibility for simplicity and subclass the Thread class.

    Definition: Mutex Lock

    A mutex lock is also known as a mutually exclusive lock. This type of lock is provided by many threading systems as a means of synchronization. Only one thread can grab a mutex at a time: if two threads try to grab a mutex, only one succeeds. The other thread has to wait until the first thread releases the lock before it can grab the lock and continue operation.

    In Java, every object has an associated lock. When a method is declared synchronized, the executing thread must grab the lock associated with the object before it can continue. Upon completion of the method, the lock is automatically released.


    Under the covers, the concept of synchronization is simple: when a method is declared synchronized, the thread that wants to execute the method must acquire a token, which we call a lock. Once the method has acquired (or checked out or grabbed) this lock, it executes the method and releases (or returns) the lock. No matter how the method returns梚ncluding via an exception梩he lock is released. There is only one lock per object, so if two separate threads try to call synchronized methods of the same object, only one can execute the method immediately; the other has to wait until the first thread releases the lock before it can executethe method.

    posted on 2008-10-15 18:34 picture talk 閱讀(129) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 免费一级做a爰片久久毛片潮喷| 国内少妇偷人精品视频免费| 欧美a级成人网站免费| 亚洲国产成人久久精品动漫 | 91香蕉国产线在线观看免费| 亚洲AV无码国产丝袜在线观看 | 亚洲熟妇无码久久精品| 91香蕉国产线在线观看免费| 亚洲欧洲尹人香蕉综合| 18未年禁止免费观看| 亚洲大香伊人蕉在人依线| 无码人妻一区二区三区免费手机| youjizz亚洲| 国产精品无码一区二区三区免费 | 亚洲一区免费视频| 女人18特级一级毛片免费视频| 亚洲精华国产精华精华液| 国产免费私拍一区二区三区| 一个人看的在线免费视频| 在线观看亚洲天天一三视| 两个人看的www免费| 亚洲经典在线观看| 日韩免费a级毛片无码a∨| 亚洲JLZZJLZZ少妇| 国产亚洲AV手机在线观看| 久久免费国产视频| 亚洲综合国产成人丁香五月激情| 在线日韩av永久免费观看| 香蕉免费在线视频| 亚洲精彩视频在线观看| 国产区卡一卡二卡三乱码免费| 国产免费黄色无码视频 | 亚洲人成网站在线播放2019| 亚洲国产91精品无码专区| 国产免费网站看v片在线| 亚洲免费在线视频播放| 亚洲Aⅴ无码一区二区二三区软件| 三级网站在线免费观看| 亚洲AV无码无限在线观看不卡| 亚洲七七久久精品中文国产| 亚洲免费闲人蜜桃|