生产和消费都循环50次,在不考虑正常退出的情况。 为什么下面代码只进行一次生产消费50次正常,我觉得逻辑么的问题?????
private Boolean isEmpty=true; synchronized public void push(String name,String sex){ try { if (!isEmpty){ this.notify(); System.out.println("等待生产"); this.wait(); System.out.println("开始生产"); isEmpty=false; } this.name=name; this.sex=sex; }catch (InterruptedException e){ e.printStackTrace(); } System.out.println("生产了一个"); this.isEmpty=false; } synchronized public void pop(){ try{ if (isEmpty){ this.notify(); System.out.println("等待消费"); this.wait(); System.out.println("开始消费"); this.isEmpty=true; } System.out.println("出来一个"+this.name+" "+this.sex); }catch (InterruptedException e){ e.printStackTrace(); } }