在java中可以使用join方法来实现,join会阻塞当前方法,调用的当前方法执行结束后,才会继续往下执行!
public class Foo { public Foo() { } public void A(){ System.out.println("A"); } public void B(){ System.out.println("B"); } public void C(){ System.out.println("C"); } }
public class SortContent { public static void main(String[] args) throws InterruptedException { Thread ta= new ThreadA(); Thread tb= new ThreadB(); Thread tc= new ThreadC();
//使用匿名内部类建立多线程
// Thread ta= new Thread(()->new Foo().A());
// Thread tB= new Thread(()->new Foo().B());
// Thread tC= new Thread(()->new Foo().C());
ta.start(); ta.join(); tc.start(); tc.join(); tb.start(); } }
//继承thread类实现 class ThreadA extends Thread{ @Override public void run(){ new Foo().A(); } } class ThreadB extends Thread{ @Override public void run(){ new Foo().B(); } } class ThreadC extends Thread{ @Override public void run(){ new Foo().C(); } }
标签:ACB,顺序,Thread,void,class,线程,new,Foo,public From: https://www.cnblogs.com/developS/p/17629496.html