思路分析:
线程执行顺序必须是A线程执行、B线程执行、C线程执行
A和B线程,在B线程中调用A.join()方法
B和C线程,在C线程中调用B.join()
package Thread.Test;
public class ABCDemo extends Thread {
private String threadName;
private Thread thread;
public ABCDemo(String threadName,Thread thread){
this.thread = thread;
this.threadName = threadName;
}
@Override
public void run() {
if (thread != null){
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("当前线程:"+threadName);
}
}
public class Test {
public static void main(String[] args) {
ABCDemo a = new ABCDemo("A", null);
ABCDemo b = new ABCDemo("B", a);
ABCDemo c = new ABCDemo("C", b);
a.start();
b.start();
c.start();
}
}