Consumer.java 432 Bytes
Newer Older
Luca Arrotta's avatar
Luca Arrotta committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
package producerConsumer;

public class Consumer implements Runnable {

    private final Queue queue;
    private final String id;

    public Consumer(String id, Queue q) {
        this.id = id;
        queue = q;
    }

    public void run() {
        while (true) {
            consume(queue.take());
        }
    }

    public void consume(String message) {
Michele Fiori's avatar
Michele Fiori committed
20
        System.out.println("Cons. " + id + ": " + message);
Luca Arrotta's avatar
Luca Arrotta committed
21 22
    }
}