O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required