Java 9 Concurrency Cookbook - Second Edition

Master the art of fast, effective Java development with the power of concurrent and parallel programming
Preview in Mapt

Java 9 Concurrency Cookbook - Second Edition

Javier Fernández González

1 customer reviews
Master the art of fast, effective Java development with the power of concurrent and parallel programming
Mapt Subscription
FREE
$29.99/m after trial
eBook
$28.00
RRP $39.99
Save 29%
Print + eBook
$49.99
RRP $49.99
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$28.00
$49.99
$29.99 p/m after trial
RRP $39.99
RRP $49.99
Subscription
eBook
Print + eBook
Start 30 Day Trial

Frequently bought together


Java 9 Concurrency Cookbook - Second Edition Book Cover
Java 9 Concurrency Cookbook - Second Edition
$ 39.99
$ 28.00
Kubernetes Cookbook - Second Edition Book Cover
Kubernetes Cookbook - Second Edition
$ 35.99
$ 25.20
Buy 2 for $35.00
Save $40.98
Add to Cart

Book Details

ISBN 139781787124417
Paperback594 pages

Book Description

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

Chapter 1: 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
Chapter 2: Basic Thread Synchronization
Introduction
Synchronizing a method
Using conditions in synchronized code
Synchronizing a block of code with a lock
Synchronizing data access with read/write locks
Using multiple conditions in a lock
Advanced locking with the StampedLock class
Chapter 3: 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
Chapter 4: 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
Chapter 5: Fork/Join Framework
Introduction
Creating a fork/join pool
Joining the results of the tasks
Running tasks asynchronously
Throwing exceptions in the tasks
Canceling a task
Chapter 6: 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
Chapter 7: 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
Chapter 8: 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
Chapter 9: 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
Chapter 10: 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
Chapter 11: 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

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

Authors

Table of Contents

Chapter 1: 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
Chapter 2: Basic Thread Synchronization
Introduction
Synchronizing a method
Using conditions in synchronized code
Synchronizing a block of code with a lock
Synchronizing data access with read/write locks
Using multiple conditions in a lock
Advanced locking with the StampedLock class
Chapter 3: 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
Chapter 4: 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
Chapter 5: Fork/Join Framework
Introduction
Creating a fork/join pool
Joining the results of the tasks
Running tasks asynchronously
Throwing exceptions in the tasks
Canceling a task
Chapter 6: 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
Chapter 7: 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
Chapter 8: 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
Chapter 9: 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
Chapter 10: 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
Chapter 11: 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

Book Details

ISBN 139781787124417
Paperback594 pages
Read More
From 1 reviews

Read More Reviews

Recommended for You

Java: Data Science Made Easy Book Cover
Java: Data Science Made Easy
$ 67.99
$ 47.60
Distributed Computing in Java 9 Book Cover
Distributed Computing in Java 9
$ 35.99
$ 25.20
Java 9 with JShell Book Cover
Java 9 with JShell
$ 39.99
$ 28.00
Python Machine Learning Book Cover
Python Machine Learning
$ 35.99
$ 25.20
Neural Network Programming with Java Book Cover
Neural Network Programming with Java
$ 35.99
$ 7.20
Neural Network Programming with Java - Second Edition Book Cover
Neural Network Programming with Java - Second Edition
$ 35.99
$ 25.20