天天看點

【!Important】如何保證線程執行的先後順序

1 public class Test {
 2     @SuppressWarnings("static-access")
 3     public static void main(String[] args) throws InterruptedException {
 4         Thread t1 = new Thread(new Runner());
 5         Thread t2 = new Thread(new Runner());
 6         Thread t3 = new Thread(new Runner());
 7         t1.start();
 8         t1.sleep(5000);
 9         t1.join();
10     
11         t2.start();
12         t2.sleep(1000);
13         t2.join();
14         t3.start();
15         t3.join();
16     
17     }
18     
19 }
20  
21 class Runner implements Runnable{
22  
23     @Override
24     public void run() {
25         System.out.println(Thread.currentThread().getName()+"");
26         
27     }
28     
29 }      

繼續閱讀