import java.util.concurrent.CountDownLatch; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.BrokenBarrierException; class BarriereOppgave implements Runnable { public void run() { System.out.println("naa looper barrieren"); } } class Arbeid implements Runnable { private CountDownLatch latch; private CyclicBarrier barriere; public Arbeid(CyclicBarrier barriere) { this.barriere = barriere; } @Override public void run() { for (int i = 0; i < 5; i++) { System.out.println(i); // latch.countDown(); try { barriere.await(); } catch (InterruptedException e) { System.out.println(e); } catch (BrokenBarrierException e) { System.out.println(e); } } } } class Hoved { public static void main(String[] args) { int antallTraader = 10; BarriereOppgave b1 = new BarriereOppgave(); CountDownLatch latch = new CountDownLatch(antallTraader); CyclicBarrier barriere = new CyclicBarrier(antallTraader, b1); Arbeid run1 = new Arbeid(barriere); for (int i = 0; i < antallTraader; i++) { new Thread(run1).start(); } } }