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

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

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

    神奇好望角 The Magical Cape of Good Hope

    庸人不必自擾,智者何需千慮?
    posts - 26, comments - 50, trackbacks - 0, articles - 11
      BlogJava :: 首頁 ::  :: 聯(lián)系 :: 聚合  :: 管理
    我對 Java 關(guān)鍵字 Synchronized 的新理解 My New Understanding of Java's Synchronized Keyword
      說實話,我對 Java 并發(fā)編程知之不多。我曾經(jīng)常用關(guān)鍵字 volatile 試圖“強(qiáng)制原子操作”,結(jié)果帶來的麻煩比解決的還多。Sun Java 教程中的并發(fā)課程我以前從沒看完過,現(xiàn)在該通讀一遍了。     To be honest, I knew only a little about concurrent programming in Java. I uesed to use keyword volatile as an attempt to "enforce atomic operations" which had brought me more troubles than solved. Time to walk through the Concurrency Trail of Sun's Java Tutorials that I never finished reading in the past.
      我其實知道并經(jīng)常看到關(guān)鍵字 synchronized 的使用,但直到昨天我還沒發(fā)覺就這個字消除了很多同步問題。然而,真正的答案在我第一次看這個教程時就在里面了,到這次才弄清。     I do know and often see the usage of keyword synchronized, but until yesterday I hadn't figured out how thie single word elimated so many synchronization problems. However, the very answer lies in those tutorials ever since I first read it and this time it has been clearly understood.
      每個對象都關(guān)聯(lián)有一個內(nèi)部鎖,也被稱作監(jiān)視器鎖或簡稱監(jiān)視器。當(dāng)一個線程調(diào)用一個同步方法時,它自動請求此方法的內(nèi)部鎖,并在方法返回時釋放。即使是未捕獲的異常造成了返回,也會發(fā)生鎖的釋放。而對靜態(tài)同步方法,方法所在類的 Class 對象的內(nèi)部鎖被請求。同步語句的內(nèi)部行為沒什么兩樣,只是還需要顯示指定一個需要請求其內(nèi)部鎖的任意對象。

        Every boject has an intrinsic lock, which is also known as monitor lock or monitor for short, associated with it. When a thread invokes a synchronized method, it automatically acquires the intrinsic lock for that method's object and releases it when the method returns. The lock release occurs even if the return was caused by an uncaught exception. As for a static synchronized method, an intrinsic lock for the Class object of that method's Class is acquired instead. Synchronized statements internally behaves no differently except in addition to this, an arbitrary object whose intrinsic lock will be acquired can be and should be explicitly specified.

      總之,synchronized 關(guān)鍵字是鎖定對象的簡單方式,也有很多局限。java.util.concurrency.locks 包支持更高深的鎖定用法,也是我將要學(xué)的。

        In conclusion, synchronized keyword is a simplified way of locking objects, and also has many limitations. More sophisticated locking idioms are supported by the java.util.concurrency.locks package which I am going to learn.


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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 免费大片av手机看片| 亚洲一卡二卡三卡四卡无卡麻豆| 亚洲欧洲无卡二区视頻| 国产精品1024永久免费视频 | 日本免费v片一二三区| 久久狠狠爱亚洲综合影院| 成人午夜免费福利视频| 久久亚洲AV无码精品色午夜麻豆| 97视频免费观看2区| 亚洲视频一区网站| 无码专区永久免费AV网站| 亚洲一本一道一区二区三区| 麻豆精品国产免费观看| 青草久久精品亚洲综合专区| 免费a级毛片网站| 一个人看的免费观看日本视频www| 亚洲精品国产精品国自产观看| 一个人看的免费视频www在线高清动漫| 亚洲综合国产一区二区三区| a毛片免费观看完整| 亚洲网站免费观看| 18禁超污无遮挡无码免费网站国产| 亚洲AV无码之国产精品| 久久亚洲精品无码观看不卡| 中文字幕av免费专区| 亚洲AV成人片色在线观看| 日本成年免费网站| 麻豆91免费视频| 久久国产亚洲观看| 成人免费无遮挡无码黄漫视频| 国产亚洲精品AAAA片APP| 亚洲男同帅GAY片在线观看| 在线a免费观看最新网站| 久久亚洲精品成人无码| 亚洲乱码中文字幕综合| jjizz全部免费看片| 一级做a爰片久久毛片免费陪| 亚洲av无码一区二区三区乱子伦 | 粉色视频成年免费人15次| 亚洲日本乱码在线观看| 无人在线直播免费观看|