FileDocCategorySizeDatePackage
Barrier.javaAPI DocExample2010Thu Feb 04 16:10:38 GMT 1999None

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;