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

Handling spurious thread wakeups


When multiple threads are used, one thread may need to wait until the completion of one or more other threads. When this is necessary, one approach is to use the Object class' wait method to wait for the other threads to complete. These other threads need to use either the Object class' notify or notifyAll methods to permit the thread that is waiting to continue.

However, spurious wakeup calls can occur in some situations. In Java 7, the java.awt.event.InvocationEvent class' isDispatched method has been introduced to address this problem.

Getting ready

To avoid spurious wakeup calls:

  1. 1. Add a synchronized block.

  2. 2. Create a while loop based on the results of an application-specific condition and the isDispatched method.

  3. 3. Use the wait method in the body of the loop.

How to do it...

  1. 1. Due to the nature of spurious interrupts, it is not feasible to create a demonstration application that will consistently demonstrate this behavior. The recommended way of handling...