CountDownLatch cannot be reset
A CountDownLatch reaches zero once and cannot be reused for another cycle. Use CyclicBarrier, Phaser, or a new latch when repeated coordination is required.
Clear note on java / concurrency. "CountDownLatch cannot be reset" is the kind of detail that is easy to overlook.
Treasure
Handy
- @sohmeh▲ 1
Specific and to the point: "CountDownLatch cannot be reset". Worth a look if you touch java / concurrency.
Practical
Once a CountDownLatch reaches zero it is finished, and it has no reset method. For phased work repeated many times, a Phaser or CyclicBarrier matches the pattern more closely.
A CountDownLatch counts down to zero once and then stays at zero, so it cannot coordinate a second round. Use CyclicBarrier or Phaser for repeated rounds, or create a fresh latch per round.
If a task fails before it counts down,
await()never returns, so use the timedawaitoverload. Seen another edge case with this? Add it below."CountDownLatch cannot be reset" is a useful thing to know about with java / concurrency. Thanks for sharing it.
Specific and to the point: "CountDownLatch cannot be reset". Worth a look if you touch java / concurrency.
Good to see "CountDownLatch cannot be reset" written down. Handy reference for anyone working with java / concurrency.
Clear note on java / concurrency. "CountDownLatch cannot be reset" is the kind of detail that is easy to overlook.