1: public class Consumer extends Thread {
2:
3: protected BoundedQueue queue;
4: protected int n;
5:
6: public Consumer(BoundedQueue queue, int n) {
7: this.queue = queue;
8: this.n = n;
9: }
10:
11: public void run() {
12: for (int i = 0; i < n; i++) {
13: Object obj = queue.get();
14: if (obj != null)
15: System.out.println("\tconsume: "+obj);
16: try {
17: sleep((int)(Math.random() * 400));
18: } catch (InterruptedException e) {}
19: }
20: }
21: }