demibug

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            24 Posts :: 3 Stories :: 2 Comments :: 0 Trackbacks
          Atomic action cannot stop in the middle: it either happens completely, or it doesn't happen at all. No side effects of an atomic action are visiable until the action is complete.

          Java primitive types include: byte; short; int; long; float; double; boolean; char;

          讀和寫變量的引用以及primitive types的變量的操作是原子的(除了long和double);
          讀和寫任何用volatile關鍵字修飾的變量的操作是原子的(包括long和double);

          Primitive 類型并不能完全消除同步錯誤,原子操作有時仍需同步,使用volatile修飾能避免這些錯誤。(用volatile修飾的primitive types)

          那么什么時候會發生這種錯誤呢,即在不同線程對primitive類型變量進行賦值時,這種錯誤是可能發生的。(只在不同線程讀取primitive類型變量不會產生這種錯誤)
          posted on 2012-11-17 00:52 Hiji 閱讀(196) 評論(0)  編輯  收藏
          主站蜘蛛池模板: 休宁县| 屯留县| 新龙县| 沂水县| 安泽县| 新宾| 绍兴县| 巧家县| 扶风县| 寿阳县| 通山县| 腾冲县| 旺苍县| 南溪县| 信宜市| 嵊泗县| 逊克县| 海林市| 隆尧县| 佛学| 康马县| 天长市| 兴安盟| 缙云县| 斗六市| 高雄市| 花垣县| 江阴市| 丘北县| 依兰县| 武威市| 东辽县| 浪卡子县| 诸城市| 泸州市| 昌吉市| 土默特左旗| 浑源县| 海宁市| 肇源县| 泗洪县|