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

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ### 等待與通知 wait方法的語義有兩個,一個是釋放當前的對象鎖、另一個是使得當前線程進入阻塞隊列, 而這些操作都和監視器是相關的,所以wait必須要獲得一個監視器鎖 ``` public final void wait() throws InterruptedException; public final native void notify(); public final native void notifyAll(); ``` #### obj.wait\(\)喚醒條件 * 其它線程調用了obj.notify\(\); * 其它線程調用了obj.notifyAll\(\); * wait\(毫秒數\)達到指定的時間后自然被激活 說明:在SUN Jdk中,object.wait\(\)還有可能被假喚醒,因此在object.wait被喚醒后應再次確認需要等待的狀態是否變更了,如果未變更則繼續進入wait狀態,這種做法通稱為double check ![](https://img.kancloud.cn/7b/04/7b04c75e76f112dd968991e1b4ebb4cd_1790x332.png) ### 中斷響應 wait方法支持響應中斷 ``` public final void wait() throws InterruptedException { wait(0); } public final native void wait(long timeout) throws InterruptedException; ``` 示例: ``` public class Appliction { private static Object lock = new Object(); public static void main(String[] args) throws InterruptedException { Thread thread = new Thread(() -> { synchronized (lock){ try { lock.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } System.err.println(Thread.currentThread().getName() + " canceled===>"); }); thread.start(); TimeUnit.SECONDS.sleep(3); thread.interrupt(); System.err.println(Thread.currentThread().getName() + " finished===>"); } } ``` #### 知識點 * wait\(\)方法在執行后會釋放監視鎖 * Object.wait\(\)與Thread.sleep\(\)方法的主要區別是wait\(\)方法會釋放目標對象的監視鎖,而sleep\(\)方法不會釋放任何資源
                  <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>

                              哎呀哎呀视频在线观看