From 2bdd4bd722000012b10d7ec27e9ec303fa3bd0be Mon Sep 17 00:00:00 2001 From: Senjars Date: Mon, 16 Mar 2026 18:24:01 +0100 Subject: [PATCH 1/2] BlockingQueue --- src/main/java/core/basesyntax/BlockingQueue.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/core/basesyntax/BlockingQueue.java b/src/main/java/core/basesyntax/BlockingQueue.java index 77a20440..1969e805 100644 --- a/src/main/java/core/basesyntax/BlockingQueue.java +++ b/src/main/java/core/basesyntax/BlockingQueue.java @@ -12,16 +12,22 @@ 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(queue.isEmpty()) { + wait(); + } + notifyAll(); + return queue.poll(); } public synchronized boolean isEmpty() { - // write your code here - return true; + return queue.isEmpty(); } } From dc562e85d1851915f9b6b836fdbfae2026f1d87d Mon Sep 17 00:00:00 2001 From: Senjars Date: Mon, 16 Mar 2026 18:26:23 +0100 Subject: [PATCH 2/2] checkstyle fixes --- src/main/java/core/basesyntax/BlockingQueue.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/core/basesyntax/BlockingQueue.java b/src/main/java/core/basesyntax/BlockingQueue.java index 1969e805..30b31b9c 100644 --- a/src/main/java/core/basesyntax/BlockingQueue.java +++ b/src/main/java/core/basesyntax/BlockingQueue.java @@ -12,7 +12,7 @@ public BlockingQueue(int capacity) { } public synchronized void put(T element) throws InterruptedException { - while(queue.size() == capacity) { + while (queue.size() == capacity) { wait(); } queue.add(element); @@ -20,7 +20,7 @@ public synchronized void put(T element) throws InterruptedException { } public synchronized T take() throws InterruptedException { - while(queue.isEmpty()) { + while (queue.isEmpty()) { wait(); } notifyAll();