I got a bunch of threads that perform calculations. They are "synchronized" using a CyclicBarrier
. When any thread's run()
method finishes, I want all other threads to exit as well once they call await()
on the barrier the next time.
So far, everything I've tried either hangs at the await()
calls or results in a broken barrier. Any tips?
EDIT: Here's the (basic) code:
public MyClass implements Runnable {
public void run() {
while (true) {
if (someCondition) {
// quit other threads when they call await()
return;
}
barrier.await();
}
}