public class Traadeksempel { public static void main(String[] args) { Thread[] traader = new Thread[5]; for (int i = 0; i < 5; i++) { traader[i] = new Thread(new Arbeider(i)); traader[i].start(); } for (int i = 0; i < 5; i++) { try { traader[i].join(); } catch (InterruptedException e) { e.printStackTrace(); } } System.out.println("Alle arbeidere er ferdige."); } } class Arbeider implements Runnable { int id; public Arbeider(int id) { this.id = id; } public void run() { System.out.printf("Arbeider %d sier: Hei!%n", id); } }