The most important element in a concurrent API is the synchronization mechanism it offers to the programmer. Synchronization is the coordination of two or more tasks to get the desired result. You can synchronize the execution of two or more tasks, when they have to be executed in a predefined order, or synchronize the access to a shared resource, when only one thread at a time can execute a fragment of code or modify a block of memory. The Java 9 concurrency API provides a lot of synchronization mechanisms, from the basic synchronized keyword and the Lock interface and their implementations, to protect a critical section, to the more advanced CyclicBarrier or CountDownLatch classes, which allow you to synchronize the order of execution of different tasks. In Java 7, the concurrency API introduces the Phaser class. This class...




















































