The cyclicbarrier in the Concurrent Concurrency Library package introduced by Java 5 is a synchronous helper class that allows a set of threads to wait until they reach a common barrier point (common barrier points). In programs that involve a set of fixed-size threads, these threads have to wait for each other, and cyclicbarrier is useful at this time. Because the barrier can be reused after releasing the waiting thread, it is called a cyclic barrier. Cyclicbarrier supports an optional Runnable command that runs only once at each barrier point after the last thread in a set of threads arrives (but before releasing all threads). This barrier operation is useful if you update the shared state before continuing with all participating threads. For example: In a certain demand, a large task, often need to allocate a lot of sub-tasks to execute, only when all the subtasks are completed to perform the main task, this time, you can choose Cyclicbarrier.
Cyclicbarrier in Java concurrent programming for a set of threads to wait for each other