票据为同步资源:每一时刻资源池中仅存在一张可供使用的票据
public class Ticket {private int ticket=-1;synchronized public void setTicket(int ticket)//生产票据{if(this.ticket!=-1)try {wait();} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}this.ticket=ticket;System.out.println("生产产品"+this.getClass().getName()+this.ticket);notify();}synchronized public void getTicket()//消费票据 {if(this.ticket==-1)try {wait();} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}System.out.println("消费产品"+this.getClass().getName()+this.ticket); this.ticket=-1; notify();}}public class Tic