Follow these steps to implement the example:
- Create a class named AddTask and specify that it implements the Runnable interface:
public class AddTask implements Runnable {
- Declare a private ConcurrentLinkedDeque attribute parameterized by the String class named list:
private final ConcurrentLinkedDeque<String> list;
- Implement the constructor of the class to initialize its attribute:
public AddTask(ConcurrentLinkedDeque<String> list) { this.list=list; }
- 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(); ...