诸如这个线程
- Java code
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+"瓶啤酒!"); } }
测试方法如果只是如是写,怎么才能醒?
- Java code
public static void main(String[] args) { Winebottle wb = new Winebottle(); ProduceBeer pb = new ProduceBeer(wb); new Thread(wb).start(); new Thread(pb).start(); }
------解决方案--------------------------------------------------------
没有明白你的意思。
什么叫 :“只是如是写,怎么才能醒”
你的分是越来越少哈!