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 video will take you through all the new APIs, showing you how to build parallel and multi-threaded applications. The video 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 video, 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.
About the author
Javier Fernández González is a software architect with almost 15 years experience in Java technologies. He has worked as a teacher, researcher, programmer, analyst, and writer, and he now works as an architect in all types of projects related to Java, especially J2EE. As a teacher has over 1,000 hours of training in basic Java, J2EE, and the Struts framework. As a researcher, he has worked in the field of information retrieval, developing applications for processing large amounts of data in Java, and has participated as a co-author in several journal articles and conference presentations. Recently, he worked on developing J2EE web applications for various clients from different sectors (public administration, insurance, healthcare, transportation, and so on). He has also worked as a software architect. He is the author of the books, Java 7 Concurrency Cookbook and Mastering Concurrency Programming with Java 8 by Packt.
Build a class that implements the Runnable interface and the run method to create an object of the Thread class.
Java provides an interruption mechanism that indicates to a thread that you want to finish it.
The thread implements a complex algorithm divided into some methods, or it has methods with recursive calls. Java provides the InterruptedException exception.
The thread doesn't use any resources of the computer.Use the sleep method of the Thread class.
In some situations, we will have to wait for the end of the execution of a thread (the run() method ends its execution). We can use the join() method of the Thread class.
Java has a special kind of thread called daemon thread. Daemon threads are normally used as service providers for normal threads running in the same program.
The Java programming language, as almost all modern programming languages, implements an exception-based mechanism to manage error situations.
One of the most critical aspects of a concurrent application is shared data. This has a special importance in objects that extend the Thread class or implement the Runnable interface. The Java Concurrency API provides a clean mechanism called thread-local variables.
An interesting functionality offered by the concurrency API of Java is the ability to group threads.Java provides the ThreadGroup class to work with a group of threads.
The factory pattern is one of the most used design patterns, and its objective is to develop an object whose mission is to create other objects of one or several classes. Java provides the ThreadFactory interface to implement a thread object factory.
The most basic methods of synchronization in Java is the use of the synchronized keyword to control concurrent access to a method or a block of code
A classic problem in concurrent programming is the producer-consumer problem. We will implement the producer-consumer problem using thesynchronized keyword and the wait(), notify(), and notifyAll() methods.
Java provides another mechanism for synchronizing blocks of code. It's based on the Lock interface and classes.
One of the most significant improvements offered by locks is the ReadWriteLock interface and the ReentrantReadWriteLock class; the unique class that implements that interface.
A classic problem in concurrent programming is the producer-consumer problem. We will implement the producer-consumer problem using locks and conditions.
The StampedLock class provides a special kind of lock that is different from the ones provided by the Lock or ReadWriteLock interfaces.
The Java language provides the semaphore mechanism. A semaphore is a counter that protects access to one or more shared resources.
The Java concurrency API provides a class that allows one or more threads to wait until aset of operations are done. It's called the CountDownLatch class.
The Java concurrency API provides a synchronizing utility that allows the synchronization of two or more threads at a determined point. It's the CyclicBarrier class.
One of the most complex and powerful functionalities offered by the Java concurrency API is the ability to execute concurrent-phased tasks using the Phaser class. This mechanism is useful when we have some concurrent tasks divided into steps.
The Phaser class provides a method that is executed every time the phaser changes the phase,using the onAdvance() method.
The Java concurrency API provides a synchronization utility that allows the exchange of data between two concurrent tasks.The Exchanger class allows you to have adefinition of a synchronization point between two threads.
The Java 8 Concurrency API includes a new synchronization mechanism with the CompletableFuture class. This class implements the Future object and the CompletionStage interface.
Packt has been committed to developer learning since 2004. A lot has changed in software since then - but Packt has remained responsive to these changes, continuing to look forward at the trends and tools defining the way we work and live. And how to put them to work.
With an extensive library of content - more than 4000 books and video courses -Packt's mission is to help developers stay relevant in a rapidly changing world. From new web frameworks and programming languages, to cutting edge data analytics, and DevOps, Packt takes software professionals in every field to what's important to them now.
From skills that will help you to develop and future proof your career to immediate solutions to every day tech challenges, Packt is a go-to resource to make you a better, smarter developer.
Packt Udemy courses continue this tradition, bringing you comprehensive yet concise video courses straight from the experts.