class BarrierTest extends Concurrent { BarrierTest(Barrier[] args) { super(args); } private void a() { System.out.println(Thread.currentThread().getName() + ": a()"); } private void b() { System.out.println(Thread.currentThread().getName() + ": b()"); } protected void perform(Barrier barrier) { a(); int position = 0; try { position = barrier.await(); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(Thread.currentThread().getName() + " hat als " + position + ". die Barriere erreicht und sie inzwischen überschritten"); b(); } public static void main(String[] args) throws InterruptedException { Barrier b = new Barrier(10); // Zahl muss gleich Anzahl Barriers im barrierArray sein Barrier[] barrierArray = new Barrier[] {b, b, b, b, b, b, b, b, b , b}; // alle Threads benutzen dieselbe Barriere b new BarrierTest(barrierArray).run(); } }