How to do it...

Perform the following steps to implement the example:

  1. Create a class named Producer and specify that it implements the Runnable interface:
        public class Producer implements Runnable { 
  1. Declare a private LinkedTransferQueue attribute parameterized with the String class named buffer:
        private LinkedTransferQueue<String> buffer; 
  1. Declare a private String attribute named name to store the name of the producer:
        private String name; 
  1. Implement the constructor of the class to initialize its attributes:
        public Producer(String name, LinkedTransferQueue<String> buffer){           this.name=name;           this.buffer=buffer;         } 
  1. Implement the run() method. Store 10,000 strings in the buffer using the put() method of the buffer object and write ...

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.