package com.neutron.thread.wait_notifyall;
/**
* 生产者
* @author zhanght
*
*/
public class Producter implements Runnable {
private Resource res;
public Producter(Resource res) {
this.res = res;
}
@Override
public void run() {
while(true) {
res.set("土豆");
}
}
}
package com.neutron.thread.wait_notifyall;
public class Consumer implements Runnable {
private Resource res;
public Consumer(Resource res) {
this.res = res;
}
@Override
public void run() {
while (true) {
res.get();
}
}
}
package com.neutron.thread.wait_notifyall;
public class ProCon {
public static void main(String[] args) {
Resource res = new Resource();
Producter pro1 = new Producter(res);
Producter pro2 = new Producter(res);
Consumer con1 = new Consumer(res);
Consumer con2 = new Consumer(res);
new Thread(pro1).start();
new Thread(pro2).start();
new Thread(con1).start();
new Thread(con2).start();
}
}