Barrier A cyclic barrier is a reasonable choice for a barrier in contexts involving a fixed sized group of threads that must occasionally wait for each other. This is usually the simplest and best strategy for sharing knowledge about failures among cooperating threads in the most common usages contexts of Barriers. This transmits breakage as early as possible, but with the possible byproduct that only some threads returning out of a barrier will realize that it is newly broken.
Barriers support an optional Runnable command that is run once per barrier point.
Here is a code sketch of a barrier in a parallel decomposition design. Return the number of parties that must meet per barrier point. This command is run exactly once, by the thread that trips the barrier. The command is not run if the barrier is broken. If null, no command is run.