O'Reilly logo

Java 7 Concurrency Cookbook 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

Using non-blocking thread-safe lists

The most basic collection is the list. A list has an undetermined number of elements and you can add, read, or remove the element of any position. Concurrent lists allow the various threads to add or remove elements in the list at a time without producing any data inconsistency.

In this recipe, you will learn how to use non-blocking lists in your concurrent programs. Non-blocking lists provide operations that, if the operation can't be done immediately (for example, you want to get an element of the list and the list is empty), they throw an exception or return a null value, depending on the operation. Java 7 has introduced the ConcurrentLinkedDeque class that implements a non-blocking concurrent list.

We are ...

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