How to do it...

Follow these steps to implement the example:

  1. Create a class named AddTask and specify that it implements the Runnable interface:
        public class AddTask implements Runnable {
  1. Declare a private ConcurrentLinkedDeque attribute parameterized by the String class named list:
        private final ConcurrentLinkedDeque<String> list;
  1. Implement the constructor of the class to initialize its attribute:
        public AddTask(ConcurrentLinkedDeque<String> list) {          this.list=list;         }
  1. Implement the run() method of the class. This method will have a loop with 5000 cycles. In each cycle, we will take the first and last elements of the deque so we will take a total of 10,000 elements:
        @Override         public void run() {  String name=Thread.currentThread().getName(); ...

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.