CyclicBarrier is cyclic because it can be reused without reset. From javadoc
A synchronization tool that allows all threads to wait for each other to reach a common barrier point. CyclicBarriers are useful in programs that include a group of fixed-size threads that sometimes need to wait for each other. The barrier is called circular because it can be reused after the release of pending threads.
Thus, in normal use, when all flows are collected and the barrier is broken, it is reset and can be used again.
From Javadoc to reset()
Resets the barrier to its original state. If either party is currently waiting at the barrier, they will return with a BrokenBarrierException . Please note that resetting after a breakdown for other reasons may be difficult to perform; threads must be re-synchronized in a different way and choose one to perform a reset. It may be preferable to instead create a new barrier for future use.
Thus, reset causes all currently BrokenBarrierException streams and immediately BrokenBarrierException . reset used when you want to break the barrier.
Please also note the caution - after forced waking up the threads, it will be difficult to synchronize them again.
TL; DR : you never need to use reset() in normal circumstances.
Boris the Spider
source share