From 4944ab5be63b34521f6830b15974050f6a22facd Mon Sep 17 00:00:00 2001 From: larsu Date: Fri, 6 Feb 2026 18:23:10 +0400 Subject: [PATCH] implemented synchronized methods in BlockingQueue --- src/main/java/core/basesyntax/BlockingQueue.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/core/basesyntax/BlockingQueue.java b/src/main/java/core/basesyntax/BlockingQueue.java index 77a20440..731ff24c 100644 --- a/src/main/java/core/basesyntax/BlockingQueue.java +++ b/src/main/java/core/basesyntax/BlockingQueue.java @@ -13,15 +13,25 @@ public BlockingQueue(int capacity) { public synchronized void put(T element) throws InterruptedException { // write your code here + while (queue.size() == capacity) { + wait(); + } + queue.offer(element); + notify(); } public synchronized T take() throws InterruptedException { // write your code here - return null; + while (isEmpty()) { + wait(); + } + T element = queue.poll(); + notify(); + return element; } public synchronized boolean isEmpty() { // write your code here - return true; + return queue.isEmpty(); } }