title: Cyclic Barrier Exception Handling
body: <p>I am facing an issue with Cyclic barrier, please look in to the code below -</p>
  
  <p>MeetingPoint1.java</p>
  
  <pre><code>public class MeetingPoint1 implements Runnable{
  
      @Override
      public void run() {
          System.out.println(" MeetingPoint1 one cleared... ");
      }
  
  }
  </code></pre>
  
  <p>MeetingPoint2.java</p>
  
  <pre><code>public class MeetingPoint2 implements Runnable{
  
      @Override
      public void run() {
          System.out.println(" MeetingPoint Two cleared... ");
      }
  
  }
  </code></pre>
  
  <p>VehicalRunnable.java</p>
  
  <pre><code>import java.util.concurrent.BrokenBarrierException;
  import java.util.concurrent.CyclicBarrier;
  
  /**
   * @author chouhan_r
   *
   */
  public class VehicleRunnable implements Runnable {
  
      private CyclicBarrier barrier1; 
      private CyclicBarrier barrier2;
  
      public VehicleRunnable(CyclicBarrier barrier1, CyclicBarrier barrier2) {
          this.barrier1 = barrier1;
          this.barrier2 = barrier2;
      }
  
      /* (non-Javadoc)
       * @see java.lang.Runnable#run()
       */
      @Override
      public void run() {
          try {
              Thread.sleep(1000);
              System.out.println(Thread.currentThread().getName() +" Waiting at Meeting Point 1");
              if(Thread.currentThread().getName().equalsIgnoreCase("Car")){
                  throw new RuntimeException("something weird happened");
              }
              barrier1.await();
              Thread.sleep(1000);
              System.out.println(Thread.currentThread().getName() +" Waiting at Meeting Point 2");
              barrier2.await();
  
          } catch(BrokenBarrierException | RuntimeException | InterruptedException e){
              e.printStackTrace();
          }
  
      }
  
  }
  </code></pre>
  
  <p>CyclicBarrierMain.java</p>
  
  <pre><code>import java.util.concurrent.CyclicBarrier;
  
  /**
   * @author chouhan_r
   *
   */
  public class CyclicBarrierMain {
  
      /**
       * @param args
       */
      public static void main(String[] args) {
          MeetingPoint1 meetingPoint1 = new MeetingPoint1();
          MeetingPoint2 meetingPoint2 = new MeetingPoint2();
  
          CyclicBarrier barrier1 = new CyclicBarrier(3, meetingPoint1);
          CyclicBarrier barrier2 = new CyclicBarrier(3, meetingPoint2);
  
          VehicleRunnable car = new VehicleRunnable(barrier1, barrier2);
          VehicleRunnable bike = new VehicleRunnable(barrier1, barrier2);
          VehicleRunnable bus= new VehicleRunnable(barrier1, barrier2);
          new Thread(car,"Car").start();
          new Thread(bike,"Bike").start();
          new Thread(bus,"Bus").start();
      }
  
  }
  </code></pre>
  
  <p>When the thread throws some exception all other threads wait at the barrier1 is there any way to run the waiting threads till barrier2 ?? Is it a better Idea to put the barrier.await() method inside the finally block ??</p>