public static void main()
{
Resource r = new Resource();
Producer pro = new Producer(r);
Consumer con = new Consumer(r);
Thread t1 = new Thread(pro);
Thread t2= new Thread(con);
t1.start();
t2.start();
}
class Resource
{
private String name;
private int count = 1;
private bolean flag = flag;
public synchroized void set(String name)
{
}
public synchroized void out()
{
}
}
class Producer implements Runnable
{
private Resource res;
Producer(Resource res)
{
this.res = res;
}
public void run()
{
while(true)
{
res.set("shangpin");
}
}
}
class Consumer implements Runnable
{
private Resource res;
Producer(Resource res)
{
this.res = res;
}
public void run()
{
while(true)
{
res.out();
}
}
}