日期:2014-05-20 浏览次数:20667 次
public synchronized void productBeer(){ while(true){ if(wb.bottlenumber==0) try { this.wait(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } wb.bottlenumber--; beernumber++; System.out.println("生产了"+beernumber+"瓶啤酒!"); } }
public static void main(String[] args) { Winebottle wb = new Winebottle(); ProduceBeer pb = new ProduceBeer(wb); new Thread(wb).start(); new Thread(pb).start(); }