Book Image

Java 7 New Features Cookbook

By : Richard M. Reese, Jennifer L. Reese
Book Image

Java 7 New Features Cookbook

By: Richard M. Reese, Jennifer L. Reese

Overview of this book

<p>Java 7 is a major update that includes a lot of exciting new language improvements such as support for type inference and improved exception handling. Other new features include the ability to work with symbolic links, a greatly simplified directory traversal technique, and the monitoring of file creation and deletion. Improvements in event handling, security, and concurrent processing have also been added<br /><br />Java 7 New Features Cookbook is your go-to guide to learn about all the new exciting features Java 7 has to offer with a very practical recipe-based approach. <br /><br />The book starts with coverage of the new language improvements. Subsequent chapters address the new features of Java 7 while incorporating these new language improvements when possible.<br /><br />The new NIO techniques provide enhanced capabilities which are complemented by the new try-with-resources block and enhanced generic support. The new JLayer decorator and improved window methods enhance the developer&rsquo;s ability to create GUI applications. <br /><br />The Java 7 New Features Cookbook provides a comprehensive coverage of the exciting features in Java 7.</p>
Table of Contents (18 chapters)
Java 7 New Features Cookbook
Credits
About the Authors
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface

Using the new ConcurrentLinkedDeque safely with multiple threads


The java.util.concurrent.ConcurrentLinkedDeque class, which is a member of the Java Collections Framework, offers the ability for multiple threads to safely access the same data collection concurrently. The class implements a double-ended queue, known as a deque, and allows for the insertion and removal of elements from both ends of the deque. It is also known as a head-tail linked list and, like other concurrent collections, does not allow the usage of null elements.

In this recipe we will demonstrate a basic implementation of the ConcurrentLinkedDeque class and illustrate the use of some of the most common methods.

Getting ready

To use a ConcurrentLinkedDeque in a producer/consumer framework:

  1. 1. Create an instance of a ConcurrentLinkedDeque.

  2. 2. Define the element to place into the deque.

  3. 3. Implement a producer thread to generate elements to be placed in the deque.

  4. 4. Implement a consumer thread to remove elements from the deque...