From 1914d6a5bf665114ec715cad4f7fded5bea4d912 Mon Sep 17 00:00:00 2001 From: Maks Date: Fri, 8 May 2026 18:17:06 +0300 Subject: [PATCH] implemented BlockingQueue class --- 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..f7f37d7a 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) { + this.wait(); + } + queue.add(element); + this.notifyAll(); } public synchronized T take() throws InterruptedException { - // write your code here - return null; + while (queue.isEmpty()) { + this.wait(); + } + this.notifyAll(); + return queue.poll(); } public synchronized boolean isEmpty() { - // write your code here - return true; + return queue.isEmpty(); } }