zoukankan      html  css  js  c++  java
  • 练习四

    package zuoYe03;
    
    public class Sickness {
    
        public static void main(String[] args) {
    
            // 特需房
            Thread t2 = new Thread("特需号") {
    
                public void run() {
                    int i;
                    for (i = 1; i <= 10; i++) {
                        System.out.println(Thread.currentThread().getName() + " : " + i + "号病人在看病!");
    
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
    
                    if (i > 10) {
                        System.out.println("特需房一天看病次数已满,不能再看病!");
                    }
    
                }
            };
            // 普通号
            Thread t1 = new Thread("普通号") {
    
                public void run() {
    
                    int i;
                    for (i = 1; i <= 50; i++) {
                        System.out.println(Thread.currentThread().getName() + " : " + i + "号病人在看病!");
    
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        if (i == 10) {
    
                            try {
                                t2.join();
                            } catch (InterruptedException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }
    
                    if (i > 50) {
                        System.out.println("普通房一天看病次数已满,不能再看病!");
                    }
                }
    
            };
    
            t1.start();
            t2.start();
        }
    
    }

  • 相关阅读:
    2月24日-寒假进度24
    2月23日-寒假学习进度23
    2月22日-寒假学习进度22
    2月21日-寒假学习进度21
    第一周冲刺意见汇总
    团队绩效评估
    团队工作第七天
    团队工作第六天
    团队工作第五天
    团队工作第四天
  • 原文地址:https://www.cnblogs.com/bichen-01/p/11309115.html
Copyright © 2011-2022 走看看