}
}
Thread.sleep(1000);
}
while (!fifo.isEmpty()) {
synchronized (fifo) {
//调用remove()方法移除一项
Object obj = fifo.remove();
print("DATA-OUT - did remove(), obj=" + obj);
}
Thread.sleep(1000);
}
print("leaving consumer()");
}
catch (InterruptedException ix) {
return;
}
}
private static void producer(ObjectFIFO fifo) {
try {
print("just entered producer()");
int count = 0;
Object obj0 = new Integer(count);
count++;
synchronized (fifo) {
//想数组之中放入一个对象
fifo.add(obj0);
print("DATA-IN - did add(), obj0=" + obj0);
//返回数组中的内容是否为空
boolean resultOfWait = fifo.waitUntilEmpty(500);
print("did waitUntilEmpty(500), resultOfWait=" +
resultOfWait + ", getSize()=" +
fifo.getSize());
}
//向数组中放入十个内容
for (int i = 0; i < 10; i++) {
Object obj = new Integer(count);
count++;
synchronized (fifo) {
fifo.add(obj);
print("DATA-IN - did add(), obj=" + obj);