<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 閱讀(126) 評論(0)  編輯  收藏


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


    網站導航:
     
    主站蜘蛛池模板: 亚洲久悠悠色悠在线播放| 国产成A人亚洲精V品无码 | 国产亚洲自拍一区| 精品无码专区亚洲| 国产成人3p视频免费观看| 亚洲欧美国产日韩av野草社区| 国产麻豆视频免费观看| 亚洲人精品亚洲人成在线| 成人毛片免费观看视频在线| 亚洲成a∨人片在无码2023| 又粗又大又硬又爽的免费视频| 污污的视频在线免费观看| 亚洲最大AV网站在线观看| 国产麻豆一精品一AV一免费| 亚洲黄色网址在线观看| 免费观看黄网站在线播放| 亚洲乱理伦片在线观看中字| 日韩精品亚洲专区在线观看| 久久国产美女免费观看精品| 亚洲国产精品自在在线观看| av大片在线无码免费| 羞羞视频免费观看| 亚洲无线观看国产精品| 18禁止看的免费污网站| 亚洲人成无码网站在线观看| 亚洲高清偷拍一区二区三区 | 国产精品亚洲片在线| 国产大片91精品免费观看不卡| 亚洲精品美女久久7777777| 亚洲成A人片77777国产| 麻豆成人久久精品二区三区免费 | 国产亚洲精品激情都市| 最近2019年免费中文字幕高清| 亚洲成a人无码亚洲成www牛牛| 中文亚洲成a人片在线观看| 精品免费久久久久久久| 黄色网址免费在线| 亚洲人成在线观看| 亚洲不卡无码av中文字幕| 51精品视频免费国产专区| 特黄特色的大片观看免费视频|