From 28a570fa3b4bac44e400528df65ab5f6020d4af5 Mon Sep 17 00:00:00 2001 From: Pavlo Mykhailyk Date: Tue, 17 Mar 2026 22:50:18 +0100 Subject: [PATCH] Add realization --- .../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..5fc1fd94 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.add(element); + notify(); } public synchronized T take() throws InterruptedException { - // write your code here - return null; + while (queue.size() == 0) { + wait(); + } + T element = queue.poll(); + notify(); + return element; } public synchronized boolean isEmpty() { - // write your code here - return true; + return queue.isEmpty(); } }