#271 implements producer-consumer

This commit is contained in:
hongsw
2015-10-28 09:55:05 +08:00
parent a2b8359ab5
commit 07faa2f625
11 changed files with 299 additions and 0 deletions
@@ -0,0 +1,27 @@
package com.iluwatar.producer.consumer;
import java.util.concurrent.LinkedBlockingQueue;
/**
* Class as a channel for {@link Producer}-{@link Consumer} exchange.
*/
public class ItemQueue {
private LinkedBlockingQueue<Item> queue;
public ItemQueue() {
queue = new LinkedBlockingQueue<Item>(5);
}
public void put(Item item) throws InterruptedException {
queue.put(item);
}
public Item take() throws InterruptedException {
return queue.take();
}
}