Follow these steps to implement the example:
- Create a class named MyPriorityTransferQueue that extends the PriorityBlockingQueue class and implements the TransferQueue interface:
public class MyPriorityTransferQueue<E> extends PriorityBlockingQueue<E> implements TransferQueue<E> {
- Declare a private AtomicInteger attribute named counter to store the number of consumers that are waiting to consume elements:
private final AtomicInteger counter;
- Declare a private LinkedBlockingQueue attribute named transferred:
private final LinkedBlockingQueue<E> transfered;
- Declare a private ReentrantLock attribute named lock:
private final ReentrantLock lock;
- Implement the constructor of the class to initialize its attributes: ...