From dc80caa6887f9a45853a5a697a8bd29ab2bbb105 Mon Sep 17 00:00:00 2001 From: Yura Kukharenko Date: Wed, 4 Mar 2026 12:56:37 +0200 Subject: [PATCH] Implement blocking queue --- .../java/core/basesyntax/BlockingQueue.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/core/basesyntax/BlockingQueue.java b/src/main/java/core/basesyntax/BlockingQueue.java index 77a20440..d342a727 100644 --- a/src/main/java/core/basesyntax/BlockingQueue.java +++ b/src/main/java/core/basesyntax/BlockingQueue.java @@ -12,16 +12,23 @@ public BlockingQueue(int capacity) { } public synchronized void put(T element) throws InterruptedException { - // write your code here + while (queue.size() == capacity) { + wait(); + } + queue.offer(element); + notifyAll(); } public synchronized T take() throws InterruptedException { - // write your code here - return null; + while (isEmpty()) { + wait(); + } + T element = queue.poll(); + notifyAll(); + return element; } public synchronized boolean isEmpty() { - // write your code here - return true; + return queue.isEmpty(); } }