public class JoinDemo implements Runnable{
public void run(){
for(int i = 0; i < 70; i++){
System.out.println(Thread.currentThread().getName() + "-----"+i);
}
}
public static void main(String args[]) throws InterruptedException{
Thread t1 = new Thread(new JoinDemo());
Thread t2 = new Thread(new JoinDemo());
t1.start();
t1.join(); //等待该线程终止,当主线程长执行到这里时,主线程会处于等待状态,等t1线程执行完后才执行
t2.start();
for(int i = 0; i < 70; i++){
System.out.println(Thread.currentThread().getName() + "----"+i);
}
}
}