Grokking Java Interview Questions
Vote

0% completed

​

Implement a Blocking Queue

A checkout thread must pass 7 orders, with the ids 1001 to 1007, to a packing thread. The shelf between them has 2 places. When the shelf holds 2 orders, the checkout thread must wait for a free place. When it holds 0, the packing thread must wait for an order.

A queue that makes threads wait in both situations is called a blocking queue. The JDK contains several, and building one shows how a lock, a condition, and a wakeup work together. The solution below starts with an array, adds one wait set, and then replaces it with two conditions.

The Problem

Write a class `BoundedQueue<T>

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content