FileDocCategorySizeDatePackage
Barrier.javaAPI DocExample2465Thu Mar 11 22:42:42 GMT 2004javathreads.examples.appa

Barrier

public class Barrier extends Object

Fields Summary
private int
threads2Wait4
private InterruptedException
iex
Constructors Summary
public Barrier(int nThreads)

                threads2Wait4 = nThreads;
        
Methods Summary
public synchronized voidfreeAll()

                iex = new InterruptedException("Barrier Released by freeAll");
                notifyAll();
        
public synchronized intwaitForRest()

                int threadNum = --threads2Wait4;

                if (iex != null) throw iex;
                if (threads2Wait4 <= 0) {
                        notifyAll();
                        return threadNum;
                }
                while (threads2Wait4 > 0) {
                        if (iex != null) throw iex;
                        try {
                                wait();
                        } catch (InterruptedException ex) {
                                iex = ex;
                                notifyAll();
                        }
                }
                return threadNum;