三个线程顺序执行

 1     static  void  test9() throws InterruptedException{
 2         Thread thread1=new Thread(()->{
 3             try {
 4                 System.out.println("111");
 5                 Thread.sleep(1000);
 6             }catch (Exception ex){}
 7 
 8          });
 9         Thread thread2=new Thread(()->{
10             try {
11                 System.out.println("222");
12                 Thread.sleep(1000);
13             }catch (Exception ex){}
14 
15         });
16         Thread thread3=new Thread(()->{
17             try {
18                 System.out.println("333");
19                 Thread.sleep(1000);
20             }catch (Exception ex){}
21 
22         });
23         thread1.start();
24         thread1.join();
25         thread2.start();
26         thread2.join();
27         thread3.start();
28         thread3.join();
29    System.out.println("main thread end");
30     }

 

posted @ 2022-03-29 10:53  甜菜波波  阅读(81)  评论(0编辑  收藏  举报