class Res
{
private String name;
private String sex;
private boolean flag=false;
public synchronized void set(String name,String sex)
{
if(flag)
try
{
this.wait();
}
catch (Exception e){}
this.name=name;
this.sex=sex;
flag =true;
this.notify();
}
public synchronized void out()
{
if(!flag)
try
{
this.wait();
}
catch (Exception e){}
System.out.println(name+"...."+sex);
flag=false;
this.notify();
}
}
同步
最新推荐文章于 2024-02-02 17:31:12 发布