import java.util.concurrent.CountDownLatch; class CLD { static class Task implements Runnable { CountDownLatch cdl; Task(CountDownLatch cdl){ this.cdl = cdl; } @Override public void run() { int var = 0; for (int i = 0; i < 1000; i++) { try { var++; Thread.sleep(1); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } System.out.println("Ferdig"); cdl.countDown(); System.out.println("Fortsetter"); } } public static void main(String[] args) throws InterruptedException { int threads = 3; CountDownLatch latch = new CountDownLatch(threads); Task t = new Task(latch); for (int i = 0; i < threads; i++) { new Thread(t).start(); } System.out.println("Venter på trådene"); latch.await(); System.out.println("Alle tråder er ferdige."); } }