这个是多线程经常会遇到的面试题,其实这个我们分析一下,无非就是在t2线程里面申明t1.join(),在t3线程里面t2.join();这样就可以了
package com.newDemo.controller.test;
public class threadDemo7 {
public static void main(String[] args) throws InterruptedException {
xiancheng1 x1=new xiancheng1();
xiancheng2 x2=new xiancheng2();
xiancheng3 x3=new xiancheng3();
Thread thread1 = new Thread(x1);
thread1.start();
Thread thread2 = new Thread(x2);
thread1.join();
thread2.start();
Thread thread3 = new Thread(x3);
thread2.join();
thread3.start();
}
}
class xiancheng1 implements Runnable{
public void run() {
for (int i = 0; i < 60; i++) {
System.out.println("子线程1=="+i);
}
}
}
class xiancheng2 implements Runnable{
public void run() {
for (int i = 0; i < 60; i++) {
System.out.println("子线程2=="+i);
}
}
}
class xiancheng3 implements Runnable{
public void run() {
for (int i = 0; i < 60; i++) {
System.out.println("子线程3=="+i);
}
}
}