How to do it...

Follow these steps to implement the example:

  1. Create a class named ProducerConsumerTest that extends the MultithreadedTestCase class:
        public class ProducerConsumerTest extends MultithreadedTestCase {
  1. Declare a private LinkedTransferQueue attribute parameterized by the String class named queue:
        private LinkedTransferQueue<String> queue;
  1. Implement the initialize() method. This method won't receive any parameters and will return no value. It will call the initialize() method of its parent class and then initialize the queue attribute:
        @Override         public void initialize() {           super.initialize();           queue=new LinkedTransferQueue<String>();           System.out.printf("Test: The test has been initialized\n");         }
  1. Implement the thread1() ...

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.