public class Phone {
String name = "Iphone";
boolean empty = true;
public synchronized void produce(String name) {
if (!empty) {
try {
super.wait(); // already have, wait
} catch (Exception e) {
}
}
this.name = name; // producing phone
empty = false;
super.notify();
}
public synchronized String comsume() {
if (empty) {
try {
super.wait(); // have to wait
} catch (Exception e) {
}
}
empty = false;
super.notify();
return this.name;
}
}
class producer{....}
class comsummer{....}
class tester{...}
没有评论:
发表评论