import java.util.concurrent.CountDownLatch; public class PizzaBaker implements Runnable { // Gir hver traad en id for aa kunne se forskjell paa dem naar vi printer private int id; private PizzaMonitor monitor; private CountDownLatch ferdigSignal; public PizzaBaker(int id, PizzaMonitor monitor, CountDownLatch ferdigSignal) { this.id = id; this.monitor = monitor; this.ferdigSignal = ferdigSignal; } @Override public void run() { try { // Vi sier at det tar 2 sekunder aa lage en pizza her Thread.sleep(2000); // Etter 2 sekunder er en pizza laget Pizza nyPizza = new Pizza(); System.out.println("Baker " + id + " laget en pizza."); monitor.leggTilPizza(nyPizza); // Signaler at bakeren er ferdig med aa legge inn pizzaen ferdigSignal.countDown(); } catch (InterruptedException e) { // Hvis traaden blir avbrutt mens den sover return; } } }