<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ### synchronized鎖對象為包裝類型\(修飾變量\) synchronized鎖對象為包裝類型時,需要考慮包裝類型的緩存,如Integer默認緩存-127~128之間的數值,所以下例中鎖a和鎖b實際鎖的是同一個對象;另外其它包裝類也需要注意類似問題\(如Byte/Short\); ``` public static Integer valueOf(int i) { if (i >= IntegerCache.low && i <= IntegerCache.high) return IntegerCache.cache[i + (-IntegerCache.low)]; return new Integer(i); } public static Short valueOf(short s) { final int offset = 128; int sAsInt = s; if (sAsInt >= -128 && sAsInt <= 127) { // must cache return ShortCache.cache[sAsInt + offset]; } return new Short(s); } ``` ``` public class ConcurrentTest { private Integer a = 100; private Integer b = 100; public static void main(String[] args) throws InterruptedException { ConcurrentTest test = new ConcurrentTest(); test.testA(); test.testB(); System.err.println("a:"+ test.a); System.err.println("b:"+ test.b); } private void testA() { new Thread(() -> { System.err.println("A thread started"); synchronized (a) { for (int i = 0; i < 10; i++) { System.err.println("a =>"); sleep(1); } } }).start(); } private void testB() { new Thread(() -> { System.err.println("B thread started"); synchronized (b){ for (int i = 0; i < 10; i++) { System.err.println("b =>"); sleep(1); } } }).start(); } } out==> //實際輸出是等打印完a才打印b A thread started a => B thread started a => a => a => a => a => a => a => a => a => b => b => b => b => b => ``` 當然實際開發過程中一般也不會使用包裝類做鎖對象!
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看