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 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() ...

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