From 4e41bcfee865fcd81b1b8299d8779dbcd770225b Mon Sep 17 00:00:00 2001 From: Petro Date: Sat, 9 May 2026 01:42:04 +0100 Subject: [PATCH] multithreading blocking queue --- src/main/java/core/basesyntax/BlockingQueue.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/core/basesyntax/BlockingQueue.java b/src/main/java/core/basesyntax/BlockingQueue.java index 77a20440..a85d0b78 100644 --- a/src/main/java/core/basesyntax/BlockingQueue.java +++ b/src/main/java/core/basesyntax/BlockingQueue.java @@ -13,15 +13,24 @@ 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.isEmpty()) { + wait(); + } + notify(); + return queue.poll(); } public synchronized boolean isEmpty() { // write your code here - return true; + return queue.isEmpty(); } }