0

Is there anyway to reset the CyclicBarrier once it breaks.

I'm running the threads in loop. I feel that doing below is not really thread-safe:

if (cyclicBarrier.await()==0) {
   cyclicBarrier.reset()
}

I was hoping there is some kind of an atomic command to do it like:

cyclicBarrier.awaitAndReset();
pom
  • 230
  • 5
  • 17
  • This is a good reference for your question. Seems like reset functionality shouldn't be used in normal circumstances as it actually breaks the barrier. https://stackoverflow.com/questions/24104642/when-to-reset-cyclicbarrier-in-java-multithreading CyclicBarrier can be reused without resetting. – AndrewG Dec 30 '19 at 21:00
  • Does this answer your question? [When to reset CyclicBarrier in java multithreading](https://stackoverflow.com/questions/24104642/when-to-reset-cyclicbarrier-in-java-multithreading) – AndrewG Dec 30 '19 at 21:01
  • Thanks! So await() inherently does what I was hoping. – pom Dec 30 '19 at 21:07
  • Yeah @pom that is correct...so I literally googled your "how to reset CyclicBarrier once it breaks" and that was the first answer haha so maybe try googling what you write before posting just to see :) – AndrewG Dec 30 '19 at 21:10
  • Okiedokie. Thanks again ;) – pom Dec 30 '19 at 21:19

0 Answers0