Skip to content

Muraveva_A_B_queue#140

Open
MuravAna wants to merge 1 commit intoLevinMK23:mainfrom
MuravAna:Muraveva_A_B_praс_6

Hidden character warning

The head ref may contain hidden characters: "Muraveva_A_B_pra\u0441_6"
Open

Muraveva_A_B_queue#140
MuravAna wants to merge 1 commit intoLevinMK23:mainfrom
MuravAna:Muraveva_A_B_praс_6

Conversation

@MuravAna
Copy link

No description provided.

Copilot AI review requested due to automatic review settings March 20, 2026 20:59
@github-actions
Copy link

Поздравляем!

Пройден усложненный набор тестов для задачи queue.

@MuravAna MuravAna changed the title queue: add code Muraveva_A_B_queue Mar 20, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements the BoundedBlockingQueue<T> lecture task by replacing stubs with a working bounded FIFO queue that blocks producers/consumers using intrinsic monitors (synchronized/wait/notifyAll).

Changes:

  • Added internal storage (Queue<T>) and capacity tracking.
  • Implemented blocking put/take with wait() loops and notifyAll().
  • Implemented size() and capacity() plus basic argument validation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +36
public synchronized void put(T item) throws InterruptedException {
if (item == null) {
throw new NullPointerException();
}
while (queue.size() == capacity) {
wait();
}
queue.add(item);
notifyAll();
}

public T take() throws InterruptedException {
return null;
public synchronized T take() throws InterruptedException {
while (queue.isEmpty()) {
wait();
}
T item = queue.poll();
notifyAll();
return item;
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no unit tests covering the blocking/interrupt behavior of this queue implementation (e.g., put blocks when full, take blocks when empty, FIFO ordering, and interruption while waiting). Given the concurrency semantics, adding JUnit tests would help prevent regressions and validate the task requirements.

Copilot uses AI. Check for mistakes.
public BoundedBlockingQueue(int capacity) {

if (capacity <= 0) {
throw new IllegalArgumentException();
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing IllegalArgumentException without a message makes it harder to debug invalid usage (e.g., when capacity <= 0). Consider including a short, descriptive message indicating the expected constraint.

Suggested change
throw new IllegalArgumentException();
throw new IllegalArgumentException("capacity must be greater than 0: " + capacity);

Copilot uses AI. Check for mistakes.

public synchronized void put(T item) throws InterruptedException {
if (item == null) {
throw new NullPointerException();
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing NullPointerException without a message makes it harder to diagnose which argument was null at call sites. Consider adding a brief message (or using a helper like Objects.requireNonNull) to clarify what was expected.

Suggested change
throw new NullPointerException();
throw new NullPointerException("item must not be null");

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants