finally
{
lock.unlock();
}
}
}
class Intput implements Runnable
{
private Res r;
Intput(Res r)
{
this.r=r;
}
public void run()
{
int x=0;
while(true)
{
try{
if(x==0)
r.setNum("zhoubin","men");
else
r.setNum("lili","women");
x=(x+1)%2;
}
catch(InterruptedException e){}
}
}
}
class Output implements Runnable
{
private Res r;
Output(Res r)
{
this.r=r;
}
public void run()
{
while(true)
{
try{
r.out();
}
catch(InterruptedException e){}
}
}
}
class Demo
{
public static void main(String[] args)
{
Res r=new Res();
new Thread(new Intput(r)).start();
new Thread(new Output(r)).start();
//new Thread(new Output(r)).start();
//new Thread(new Output(r)).start();