From ad1520e2d6eb34b771f6a5ececf8882ec60e95cb Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 1 Mar 2026 21:33:47 +0200 Subject: [PATCH] notifyAll --- .../java/core/basesyntax/BlockingQueue.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/core/basesyntax/BlockingQueue.java b/src/main/java/core/basesyntax/BlockingQueue.java index 77a20440..136dceea 100644 --- a/src/main/java/core/basesyntax/BlockingQueue.java +++ b/src/main/java/core/basesyntax/BlockingQueue.java @@ -12,16 +12,33 @@ public BlockingQueue(int capacity) { } public synchronized void put(T element) throws InterruptedException { - // write your code here + while (isFull()) { + wait(); + } + if (queue.add(element)) { + notifyAll(); + } + } + + private synchronized boolean isFull() { + return queue.size() == capacity; } public synchronized T take() throws InterruptedException { - // write your code here - return null; + while (isEmpty()) { + wait(); + } + + T result = queue.poll(); + + if (queue.isEmpty()) { + notifyAll(); + } + return result; } public synchronized boolean isEmpty() { - // write your code here - return true; + return queue.isEmpty(); } + }