How to do it...

Follow these steps to implement the example:

  1. 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> {
  1. Declare a private AtomicInteger attribute named counter to store the number of consumers that are waiting to consume elements:
        private final AtomicInteger counter;
  1. Declare a private LinkedBlockingQueue attribute named transferred:
        private final LinkedBlockingQueue<E> transfered;
  1. Declare a private ReentrantLock attribute named lock:
        private final ReentrantLock lock;
  1. Implement the constructor of the class to initialize its attributes: ...

Get Java 9 Concurrency Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.