<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 多線程死鎖案例以及查看方法 我們先定義一個類調用`DeadLock`和`OtherService`。 ```java public class DeadLockTest { public static void main(String[] args) { DeadLock deadLock = new DeadLock(); OtherService otherService = new OtherService(); deadLock.setOtherService(otherService); otherService.setDeadLock(deadLock); new Thread(() -> { while (true) { deadLock.m1(); } }, "T1").start(); new Thread(() -> { while (true) { otherService.s2(); } }, "T2").start(); } } ``` ```java public class DeadLock { private OtherService otherService; public void setOtherService(OtherService otherService) { this.otherService = otherService; } // DeadLock的實例的鎖-資源A private final Object LOCK = new Object(); public void m1() { synchronized (LOCK) { System.out.println("********m1********"); otherService.s1(); } } public void m2() { synchronized (LOCK) { System.out.println("********m2********"); } } } ``` ```java public class OtherService { private DeadLock deadLock; public void setDeadLock(DeadLock deadLock) { this.deadLock = deadLock; } // OtherService的實例的鎖-資源B private final Object LOCK = new Object(); public void s1() { synchronized (LOCK) { System.out.println("========s1========"); } } public void s2() { synchronized (LOCK) { System.out.println("========s2========"); deadLock.m2(); } } } ``` 可以看到: 線程一調用`DeadLock`的`m1`方法,`m1`使用了`DeadLock`的`LOCK`鎖,`m1`調用了`OtherService`的`s1`,`s1`使用了`DeadLock`的`LOCK`鎖,線程二調用`OtherService`的`s2`,而`s2`調用了`DeadLock`的`m2`,而m2使用的DeadLock的LOCK被m1搶占著,所以就形成了死鎖。 接下來使用`jps`和`jstack`命令來看一下: ![](https://img.kancloud.cn/55/c8/55c898c4479b17e3a06645e1ac2f88ac_960x430.gif)
                  <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>

                              哎呀哎呀视频在线观看