Book description
Master the art of fast, effective Java development with the power of concurrent and parallel programming
About This Book
Get detailed coverage of important recipes on multi-threading and parallel programming
This book takes a close look at the Java 9 APIs and their impact on concurrency
See practical examples on thread safety, high-performance classes, safe sharing, and a whole lot more
Who This Book Is For
The book is for Java developers and programmers at an intermediate to advanced level. It will be especially useful for developers who want to take advantage of task-based recipes using Java 9’s concurrent API to program thread-safe solutions.
What You Will Learn
Find out to manage the basic components of the Java Concurrency API
Use synchronization mechanisms to avoid data race conditions and other problems of concurrent applications
Separate the thread management from the rest of the application with the Executor framework
Solve problems using a parallelized version of the divide and conquer paradigm with the Fork / Join framework
Process massive data sets in an optimized way using streams and reactive streams
See which data structures we can use in concurrent applications and how to use them
Practice efficient techniques to test concurrent applications
Get to know tips and tricks to design concurrent applications
In Detail
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.
Style and approach
This recipe-based book will allow you to explore the exciting capabilities of concurrency in Java. After reading this book, you will be able to comfortably build parallel applications in Java 9.
Table of contents
- Preface
-
Thread Management
- Introduction
- Creating, running, and setting the characteristics of a thread
- Interrupting a thread
- Controlling the interruption of a thread
- Sleeping and resuming a thread
- Waiting for the finalization of a thread
- Creating and running a daemon thread
- Processing uncontrolled exceptions in a thread
- Using thread local variables
- Grouping threads and processing uncontrolled exceptions in a group of threads
- Creating threads through a factory
- Basic Thread Synchronization
-
Thread Synchronization Utilities
- Introduction
- Controlling concurrent access to one or more copies of a resource
- Waiting for multiple concurrent events
- Synchronizing tasks in a common point
- Running concurrent-phased tasks
- Controlling phase change in concurrent-phased tasks
- Exchanging data between concurrent tasks
- Completing and linking tasks asynchronously
-
Thread Executors
- Introduction
- Creating a thread executor and controlling its rejected tasks
- Executing tasks in an executor that returns a result
- Running multiple tasks and processing the first result
- Running multiple tasks and processing all the results
- Running a task in an executor after a delay
- Running a task in an executor periodically
- Canceling a task in an executor
- Controlling a task finishing in an executor
- Separating the launching of tasks and the processing of their results in an executor
- Fork/Join Framework
-
Parallel and Reactive Streams
- Introduction
- Creating streams from different sources
- Reducing the elements of a stream
- Collecting the elements of a stream
- Applying an action to every element of a stream
- Filtering the elements of a stream
- Transforming the elements of a stream
- Sorting the elements of a stream
- Verifying conditions in the elements of a stream
- Reactive programming with reactive streams
-
Concurrent Collections
- Introduction
- Using non-blocking thread-safe deques
- Using blocking thread-safe deques
- Using blocking thread-safe queue ordered by priority
- Using thread-safe lists with delayed elements
- Using thread-safe navigable maps
- Using thread-safe HashMaps
- Using atomic variables
- Using atomic arrays
- Using the volatile keyword
- Using variable handles
-
Customizing Concurrency Classes
- Introduction
- Customizing the ThreadPoolExecutor class
- Implementing a priority-based Executor class
- Implementing the ThreadFactory interface to generate custom threads
- Using our ThreadFactory in an Executor object
- Customizing tasks running in a scheduled thread pool
- Implementing the ThreadFactory interface to generate custom threads for the fork/join framework
- Customizing tasks running in the fork/join framework
- Implementing a custom Lock class
- Implementing a transfer queue-based on priorities
- Implementing your own atomic object
- Implementing your own stream generator
- Implementing your own asynchronous stream
-
Testing Concurrent Applications
- Introduction
- Monitoring a Lock interface
- Monitoring a Phaser class
- Monitoring an Executor framework
- Monitoring a fork/join pool
- Monitoring a stream
- Writing effective log messages
- Analyzing concurrent code with FindBugs
- Configuring Eclipse for debugging concurrency code
- Configuring NetBeans for debugging concurrency code
- Testing concurrency code with MultithreadedTC
- Monitoring with JConsole
-
Additional Information
- Introduction
- Processing results for Runnable objects in the Executor framework
- Processing uncontrolled exceptions in a ForkJoinPool class
- Using a blocking thread-safe queue for communicating with producers and consumers
- Monitoring a Thread class
- Monitoring a Semaphore class
- Generating concurrent random numbers
-
Concurrent Programming Design
- Introduction
- Using immutable objects when possible
- Avoiding deadlocks by ordering locks
- Using atomic variables instead of synchronization
- Holding locks for as short time as possible
- Delegating the management of threads to executors
- Using concurrent data structures instead of programming yourself
- Taking precautions using lazy initialization
- Using the fork/join framework instead of executors
- Avoiding the use of blocking operations inside a lock
- Avoiding the use of deprecated methods
- Using executors instead of thread groups
- Using streams to process big data sets
- Other tips and tricks
Product information
- Title: Java 9 Concurrency Cookbook - Second Edition
- Author(s):
- Release date: April 2017
- Publisher(s): Packt Publishing
- ISBN: 9781787124417
You might also like
book
Mastering Concurrency Programming with Java 9 - Second Edition
Master the principles to make applications robust, scalable and responsive About This Book Implement concurrent applications …
book
Mastering Concurrency Programming with Java 8
Master the principles and techniques of multithreaded programming with the Java 8 Concurrency API About This …
book
Java Threads and the Concurrency Utilities
This concise book empowers all Java developers to master the complexity of the Java thread APIs …
video
Java Concurrency, 2/e
9+ Hours of Video Instruction Java Concurrency LiveLessons, Second Edition teaches you how to develop high-quality …