Book Image

Mastering Concurrency Programming with Java 9 - Second Edition

By : Javier Fernández González
Book Image

Mastering Concurrency Programming with Java 9 - Second Edition

By: Javier Fernández González

Overview of this book

Concurrency programming allows several large tasks to be divided into smaller sub-tasks, which are further processed as individual tasks that run in parallel. Java 9 includes a comprehensive API with lots of ready-to-use components for easily implementing powerful concurrency applications, but with high flexibility so you can adapt these components to your needs. The book starts with a full description of the design principles of concurrent applications and explains how to parallelize a sequential algorithm. You will then be introduced to Threads and Runnables, which are an integral part of Java 9's concurrency API. You will see how to use all the components of the Java concurrency API, from the basics to the most advanced techniques, and will implement them in powerful real-world concurrency applications. The book ends with a detailed description of the tools and techniques you can use to test a concurrent Java application, along with a brief insight into other concurrency mechanisms in JVM.
Table of Contents (21 chapters)
Title Page
About the Author
About the Reviewer
Customer Feedback


In this chapter, we presented two examples that explored the advanced characteristics of executors. In the first example, we continued with the client/server example of Chapter 3, Managing Lots of Threads - Executors. We have implemented our own executor extending the ThreadPoolExecutor class to execute tasks by priority and to measure the executing time of tasks per user. We also included a new command to allow the cancellation of tasks.

In the second example, we explained how to use the ScheduledThreadPoolExecutor class to execute periodic tasks. We implemented two versions of a news reader. The first one showed how to use the basic functionality of the ScheduledExecutorService, and the second one showed how to override the behavior of the ScheduledExecutorService class to, for example, change the delay time between the two executions of a task.

In the next chapter, you will learn how to execute Executor tasks that return a result. If you extend the Thread class or implement the...