In this chapter, we will cover the following:
Using join/fork framework in Java 7
Using the reusable synchronization barrier Phaser
Using the ConcurrentLinkedDeque class safely with multiple threads
Using the LinkedTransferQueue class
Supporting multiple threads using the ThreadLocalRandom class
Support for concurrent applications has been improved in Java 7. Several new classes have been introduced that support the parallel execution of tasks. The ForkJoinPool
class is used for applications, which use the divide-and-conquer technique to solve a problem. Each subproblem is forked (split) as a separate thread and later joined, if necessary to provide a solution. The threads used by this class are normally subclasses of the java.util.concurrent.ForkJoinTask
class and are lightweight threads. The use of this approach is illustrated in the Using join/fork framework in Java recipe.
In addition, the java.util.concurrent.Phaser
class has been introduced to...