import java.util.concurrent.*;


/**
 * A decorator of a Runnable that can be used to coordinate
 * multiple threads of execution.
 */
public class Barriered implements Runnable
{
    private CyclicBarrier barrier;    
    private Runnable      decorated;
    

    public Barriered(Runnable decorated, CyclicBarrier barrier)
    {
        this.decorated = decorated;        
        this.barrier   = barrier;        
    }
    
    public void run()
    {
        decorated.run();

        try
        {
            barrier.await();
        }
        catch (InterruptedException ie)
        {
        }
        catch (BrokenBarrierException be)
        {
        }
    }
    
    

}
