class Input implements Runnable
{
private Res r;
Input(Res r)
{
this.r = r;
}
public void run()
{
while(true)
{
try{r.set("商品");}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 ResDemo
{
public static void main(String[] args)
{
Res r = new Res();
//创建两个生成者
new Thread(new Input(r)).start();
new Thread(new Input(r)).start();
//创建两个消费者
new Thread(new Output(r)).start();
new Thread(new Output(r)).start();
}
}