How it works...

In this recipe, you used LinkedBlockingDeque, parameterized by the String class, to work with a non-blocking concurrent deque of data.

The Client class uses the put() method to insert strings into the deque. If the deque is full (because you have created it with fixed capacity), the method will block the execution of its thread until there is empty space in the list.

The Main class uses the take() method to get strings from the deque. If the deque is empty, the method blocks the execution of its thread until there are elements in the deque.

Both the methods of the LinkedBlockingDeque class used in this example can throw an InterruptedException exception if they are interrupted while they are being blocked. So, you have to ...

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.