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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.