//當前線程等待thread線程完成後才從join()返回 package com.mao;java
import java.util.concurrent.TimeUnit;ide
public class Join {ui
public static void main(String[] args) throws Exception { 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; } System.out.println("juinr"); TimeUnit.SECONDS.sleep(4); System.out.println(Thread.currentThread().getName()+" terminate."); }
}this
class Domino implements Runnable{.net
private Thread thread; public Domino(Thread thread) { this.thread=thread; } [@Override](https://my.oschina.net/u/1162528) public void run() { // TODO Auto-generated method stub try { thread.join(); }catch(InterruptedException e) { } System.out.println(Thread.currentThread().getName()+" terminate,"); }
}線程