Is there a way to kill all the threads waiting for cyclic barrier to complete. In my scenario I have 3 threads which if meet at point A then only proceed otherwise the process should be killed. I have used cyclic barrier to check if all three threads are meeting at point A, if yes then proceed but if even 1 thread fails then how can i kill all the threads using this barrier. Thet threads are just waiting. I dont want them to wait now.
Asked
Active
Viewed 356 times
1 Answers
1
When some thread going to fail in achiving "meeting point A", it can manually break the barrier:
// Fail code
Thread.currentThread.interrupt(); // Set *interrupt* status for current thread
try {
barrier.await(); // Because of interrupt status, this will immediately throw exception and mark barrier as broken.
} catch(InterruptedException e) {}
// Other finalization code if needed.
So any other thread will get BrokenBarrierException
exception whenever it attempts to use .await
on this barrier.

Tsyvarev
- 60,011
- 17
- 110
- 153