62,615
社区成员
发帖
与我相关
我的任务
分享
class Hello
{
private String name="unknown";
private String sex="unknown";
private boolean bFull=false;
public synchronized void put(String name,String sex)
{
if(bFull)
try{wait();}catch(Exception e){}
this.name=name;
try{Thread.sleep(1);}catch(Exception e){}
this.sex=sex;
bFull=true;
notify();
}
public synchronized void get()
{
if(!bFull)
try{wait();}catch(Exception e){}
System.out.print(name);
System.out.print(":"+sex);
bFull=false;
notify();
}
}