//ȴѻ,Żclass Resource{private String name;private String sex;private boolean flag;public synchronized void set(String name,String sex){if(flag)try{this.wait();}catch(InterruptedException e){}this.name=name;this.sex=sex;flag=true;notify();}public synchronized void out(){if(!flag)try{this.wait();}catch(InterruptedException e){}System.out.println(name+"..."+sex);flag=false;notify();}}//class Input implements Runnable{Resource r;Input(Resource r){this.r=r;}public void run(){int x=0;while(true){if(x==0){r.set("mike","nan");}else{r.set("","Ů");}x=(x+1)%2;}}}//class Output implements Runnable{Resource r;Output(Resource r){this.r=r;}public void run(){while(true){r.out();}}}public class ResourceDemo_1{public static void main(String[] args){//ԴResource r=new Resource();Input in=new Input(r);Output out=new Output(r);//߳Thread t1=new Thread(in);Thread t2=new Thread(out);//߳t1.start();t2.start();}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。