Thread.join 待我称王封你为后i 2022-05-13 23:59 165阅读 0赞 > Waits for this thread to die > > 确保线程先后顺序执行 public class ThreadJoinTest { public static void main(String[] args) throws Exception { Thread thread0 = new Thread(() -> System.out.println("a is running")); Thread thread1 = new Thread(() -> System.out.println("b is running")); Thread thread2 = new Thread(() -> System.out.println("c is running")); Thread thread3 = new Thread(() -> System.out.println("d is running")); thread0.start(); thread0.join(); thread1.start(); thread1.join(); thread2.start(); thread2.join(); thread3.start(); thread3.join(); System.out.println("done"); } } 执行结果 > a is running > b is running > c is running > d is running > done
还没有评论,来说两句吧...