Java – an example of barrier decomposition
I'm reading the Book Java concurrency in practice,
Can someone give an example of how it decomposes the problem into multiple independent subproblems?
Solution
You must decompose the problem into several independent sub problems
Obstacles ensure that each party completes the first sub problem before the second sub problem starts This ensures that all data from the first subproblem is available before the second subproblem starts
When each step is actually the same and requires the same barrier again and again, use cyclicbarrier For example, this can happen when performing any type of multithreaded actual simulation, which is a step-by-step simulation Cyclicbarrier will ensure that each thread completes the given step before all threads start the next step