<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                Thread類的join方法用來使main線程進入阻塞狀態,進而等待調用join方法的線程執行,join方法有如下三種形式 ~~~ public final void join(long millis) throws InterruptedException public final void join(long millis, int nanos) throws InterruptedException public final void join() throws InterruptedException ~~~ 帶參數的join方法,表示至多等待線程A的時間,而無參數的join方法,則會一直等待線程A執行結束。通過下例來說明。首先我們看不加join方法的版本,兩個線程并行執行,在run方法中睡眠15秒后同時結束: ~~~ public static void main(String[] args) { System.out.println("Main Thread Start..."+new Date()); CreateThreadTest ctt = new CreateThreadTest(); Thread t1 = new Thread(ctt,"t1"); Thread t2 = new Thread(ctt,"t2"); t1.start(); t2.start(); } public class CreateThreadTest implements Runnable { @Override public void run() { System.out.println("線程"+Thread.currentThread().getName()+":開始運行"+new Date()); try{ Thread.sleep(15000); //doDBProcessing(); }catch(InterruptedException e){ e.printStackTrace(); } System.out.println("線程"+Thread.currentThread().getName()+":結束運行"+new Date()); } } ~~~ 結果: ~~~ Main Thread Start...Thu Jul 06 14:48:37 CST 2017 線程t1:開始運行Thu Jul 06 14:48:38 CST 2017 線程t2:開始運行Thu Jul 06 14:48:38 CST 2017 線程t2:結束運行Thu Jul 06 14:48:53 CST 2017 線程t1:結束運行Thu Jul 06 14:48:53 CST 2017 ~~~ 如果加入join()方法呢: ~~~ public static void main(String[] args) { System.out.println("Main Thread Start..."+new Date()); CreateThreadTest ctt = new CreateThreadTest(); Thread t1 = new Thread(ctt,"t1"); Thread t2 = new Thread(ctt,"t2"); try{ t1.start(); t1.join(); t2.start(); }catch(Exception e){ e.printStackTrace(); } } ~~~ 原本并行的兩個線程變為了串行執行,也就是說,父線程會等待子線程的執行完畢: ~~~ Main Thread Start...Thu Jul 06 14:53:34 CST 2017 線程t1:開始運行Thu Jul 06 14:53:34 CST 2017 線程t1:結束運行Thu Jul 06 14:53:49 CST 2017 線程t2:開始運行Thu Jul 06 14:53:49 CST 2017 線程t2:結束運行Thu Jul 06 14:54:04 CST 2017 ~~~
                  <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>

                              哎呀哎呀视频在线观看