Book Image

Java 9 Concurrency Cookbook, Second Edition - Second Edition

By : Javier Fernández González
Book Image

Java 9 Concurrency Cookbook, Second Edition - Second Edition

By: Javier Fernández González

Overview of this book

Writing concurrent and parallel programming applications is an integral skill for any Java programmer. Java 9 comes with a host of fantastic features, including significant performance improvements and new APIs. This book will take you through all the new APIs, showing you how to build parallel and multi-threaded applications. The book covers all the elements of the Java Concurrency API, with essential recipes that will help you take advantage of the exciting new capabilities. You will learn how to use parallel and reactive streams to process massive data sets. Next, you will move on to create streams and use all their intermediate and terminal operations to process big collections of data in a parallel and functional way. Further, you’ll discover a whole range of recipes for almost everything, such as thread management, synchronization, executors, parallel and reactive streams, and many more. At the end of the book, you will learn how to obtain information about the status of some of the most useful components of the Java Concurrency API and how to test concurrent applications using different tools.
Table of Contents (12 chapters)

What this book covers

Chapter 1, Thread Management, teaches you how to make basic operations with threads. The creation, execution, and status management of threads are explained through basic examples.

Chapter 2, Basic Thread Synchronization, covers how to use low-level Java mechanisms to synchronize code. Locks and the synchronized keyword are explained in detail.

Chapter 3, Thread Synchronization Utilities, teaches how to use the high-level utilities of Java to manage the synchronization between threads in Java. It includes an explanation of how to use the Phaser class to synchronize tasks divided into phases.

Chapter 4, Thread Executors, explores the delegation of thread management to executors. They allow running, managing, and getting the results of concurrent tasks.

Chapter 5, Fork/Join Framework, covers the use of the Fork/Join framework. It’s a special kind of executor oriented to execute tasks that will be divided into smaller ones using the divide and conquer technique.

Chapter 6, Parallel and Reactive Streams, teaches you how to create streams and use all its intermediate and terminal operations to process big collections of data in a parallel and functional way. Streams were introduced in Java 8. Java 9 has included some new interfaces to implement reactive streams.

Chapter 7, Concurrent Collections, explains how to use some concurrent data structures provided by the Java language. These data structures must be used in concurrent programs to avoid the use of synchronized blocks of code in their implementation.

Chapter 8, Customizing Concurrency Classes, teaches you how to adapt some of the most useful classes of the Java concurrency API to your needs.

Chapter 9, Testing Concurrent Applications, covers how to obtain information about the status of some of the most useful structures of the Java 7 concurrency API. You will also learn how to use some free tools to debug concurrent applications, such as the Eclipse, NetBeans IDE, or FindBugs applications to detect possible bugs in your applications.

Chapter 10, Additional Information, explores the notions of synchronization, the executor, the Fork/Join framework, concurrent data structures, and the monitoring of concurrent objects, which were not included in the respective chapters.

Chapter 11, Concurrent Programming Design, provides some tips that every programmer should consider when they develop a concurrent application.