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

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

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