线程控制的第四种方法:线程的合并join
public class Demo05 {
/**
* 线程的合并
*/
public static void main(String[] args)throws Exception {
Step1 step1=new Step1();
Step2 step2=new Step2();
Step3 step3=new Step3();
for (int i = 0; i < 1000; i++) {
if(i==10)
{
step1.start();
step1.join();
}
if(i==100)
{
step2.start();
step2.join();
}
if(i==500)
{
step3.start();
step3.join();
}
System.out.println("美女准备出门");
}
}
static class Step1 extends Thread{
public Step1()
{
super("刷牙");
}
@Override
public void run() {
for (int i = 0; i <100 ; i++) {
System.out.println(this.getName()+"----i="+i);
}
}
}
static class Step2 extends Thread{
public Step2()
{
super("洗脸");
}
@Override
public void run() {
for (int i = 0; i <100 ; i++) {
System.out.println(this.getName()+"----i="+i);
}
}
}
static class Step3 extends Thread{
public Step3()
{
super("画眉");
}
@Override
public void run() {
for (int i = 0; i <100 ; i++) {
System.out.println(this.getName()+"----i="+i);
}
}
}
}