练习四
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(); } }