mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-09-05 06:16:50 +00:00
#271 implements producer-consumer
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user