import java.util.concurrent.CountDownLatch; public class CountdownEksempel { public static void main(String[] args) throws InterruptedException { int antTrader = 5; CountDownLatch barrieren = new CountDownLatch(6); for (int i = 0; i < antTrader; i++) { new Thread(new Arbeider(barrieren)).start(); } Thread.sleep(3000); System.out.println(Thread.currentThread().getName() + " er ferdig"); barrieren.countDown(); barrieren.await(); System.out.println("Programmet er ferdig!"); } } class Arbeider implements Runnable { private CountDownLatch barriere; Arbeider(CountDownLatch latch) { this.barriere = latch; } public void run() { gjorArbeid(); barriere.countDown(); } void gjorArbeid(){ System.out.println("Jeg gjør litt arbeid"); } }