Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/main/java/core/basesyntax/BlockingQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@ 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 (isEmpty()) {
wait();
}
notify();
return queue.remove();
}

public synchronized boolean isEmpty() {
// write your code here
return true;
return queue.isEmpty();
}
}