From 211e6292fad3d9eef34be12221c30d3c8f030ea9 Mon Sep 17 00:00:00 2001 From: S0rbex Date: Tue, 5 May 2026 16:49:25 +0300 Subject: [PATCH 1/2] done --- .../java/core/basesyntax/BlockingQueue.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/core/basesyntax/BlockingQueue.java b/src/main/java/core/basesyntax/BlockingQueue.java index 77a20440..9b160c85 100644 --- a/src/main/java/core/basesyntax/BlockingQueue.java +++ b/src/main/java/core/basesyntax/BlockingQueue.java @@ -1,5 +1,7 @@ package core.basesyntax; +import core.basesyntax.thread.Producer; + import java.util.LinkedList; import java.util.Queue; @@ -12,16 +14,23 @@ public BlockingQueue(int capacity) { } public synchronized void put(T element) throws InterruptedException { - // write your code here + while (queue.size() == capacity) { + wait(); + } + queue.add(element); + notifyAll(); } public synchronized T take() throws InterruptedException { - // write your code here - return null; + while (isEmpty()) { + wait(); + } + T item = queue.poll(); + notifyAll(); + return item; } public synchronized boolean isEmpty() { - // write your code here - return true; + return queue.isEmpty(); } } From f19da323298e62b659f22da15969514776722817 Mon Sep 17 00:00:00 2001 From: S0rbex Date: Tue, 5 May 2026 16:50:16 +0300 Subject: [PATCH 2/2] donex2 --- src/main/java/core/basesyntax/BlockingQueue.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/core/basesyntax/BlockingQueue.java b/src/main/java/core/basesyntax/BlockingQueue.java index 9b160c85..58b2bef0 100644 --- a/src/main/java/core/basesyntax/BlockingQueue.java +++ b/src/main/java/core/basesyntax/BlockingQueue.java @@ -1,7 +1,5 @@ package core.basesyntax; -import core.basesyntax.thread.Producer; - import java.util.LinkedList; import java.util.Queue;