1 package demo7;
 2 
 3 public class Test5 {
 4     public static void main(String[] args) {
 5         MyThread5 mt = new MyThread5();
 6         Thread t = new Thread(mt);
 7         t.start();
 8 
 9         for (int i = 0; i < 50; i++) {
10             try {
11                 Thread.sleep(500);
12                 System.out.println("普通号:" + (i+1) + "号病人在看病!");
13             } catch (InterruptedException e) {
14                 e.printStackTrace();
15             }
16             if (i == 9) {
17                 try {
18                     t.join();
19                 } catch (InterruptedException e) {
20                     e.printStackTrace();
21                 }
22             }
23         }
24     }
25 }
 1 package demo7;
 2 
 3 //模拟叫号看病,特需号10个,普通号50个,看病时间特需号是普通号的2倍
 4 //叫到普通号第10号时要先看完特需号
 5 public class MyThread5 implements Runnable{
 6 
 7     public void run() {
 8         for (int i = 0; i <10; i++) {
 9             try {
10                 Thread.sleep(1000);
11                 System.out.println("特需号:"+(i+1)+"号病人在看病!");
12             } catch (InterruptedException e) {
13                 e.printStackTrace();
14             }
15             
16         }
17     }
18 }

 

posted on 2019-01-01 19:58  从零开始-白  阅读(284)  评论(0编辑  收藏  举报