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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                > ### `thread.join()` * 如果一個線程A執行了`thread.join()`語句,其含義是:當前線程A等待`thread`線程終止之后才從`thread.join()`返回。線程Thread除了提供`join()`方法之外,還提供了`join(long millis)`和`join(longmillis,int nanos)`兩個具備超時特性的方法。這兩個超時方法表示,如果線程thread在給定的超時時間里沒有終止,那么將會從該超時方法中返回。 ``` public class JoinDemo { public static void main(String[] args) { Thread previous = Thread.currentThread(); for (int i = 0; i < 10; i++) { // 每個線程擁有前一個線程的引用,需要等待前一個線程終止,才能從等待中返回 Thread thread = new Thread(new Domino(previous), String.valueOf(i)); thread.start(); previous = thread; } try { TimeUnit.SECONDS.sleep(5); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(Thread.currentThread().getName() + " terminate."); } static class Domino implements Runnable{ private Thread thread; public Domino(Thread thread){ this.thread = thread; } public void run(){ try{ thread.join(); }catch (InterruptedException e) { e.printStackTrace(); } System.out.println(Thread.currentThread().getName() + " terminate."); } } } ``` <br/> > ### `Thread.join()`源碼 當線程終止時,會調用線程自身的`notifyAll()`方法,會通知所有等待在該線程對象上的線程, ``` // 加鎖當前線程對象 public final synchronized void join() throws InterruptedException { // 條件不滿足,繼續等待 while (isAlive()) { wait(0); } // 條件符合,方法返回 } ```
                  <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>

                              哎呀哎呀视频在线观看