设计三个线程,实现动物园售票窗口进行卖票,每天总共最多只能出售100张票,售完后所有窗口都停止售票
package com.multith.java; public class Ticket implements Runnable{ private int num=100; @Override public void run() { while(true) { synchronized (this) { //同步代码块 if(num>0) { try { Thread.sleep(100); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } num--; System.out.println(Thread.currentThread().getName()+ " 卖出一张票,还剩:"+ num + "张"); }else { System.out.println(Thread.currentThread().getName()+" 票已售完!"); break; } } } } public static void main(String[] args) { Ticket tic = new Ticket(); Thread t1 = new Thread(tic,"窗口A"); Thread t2 = new Thread(tic,"窗口B")