How it works...

In this recipe, we used the ConcurrentLinkedDeque object parameterized by the String class to work with a non-blocking concurrent deque of data. The following screenshot shows the output of an execution of this example:

First, you executed 100 AddTask tasks to add elements to the list. Each one of these tasks inserts 10,000 elements to the list using the add() method. This method adds new elements at the end of the deque. When all the tasks had finished, you wrote the number of elements of the deque in the console. At that moment, the deque had 1,000,000 elements.

Then, you executed 100 PollTask tasks to remove elements from ...

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.