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

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