import java.util.concurrent.CountDownLatch; public class Hovedprogram { public static void main(String[] args) { final int ANTALL_KNIVTRAADER = 10; final int ANTALL_SAKSTRAADER = 1; KnivMonitor kMonitor = new KnivMonitor(ANTALL_KNIVTRAADER); Saksmonitor sMonitor = new Saksmonitor(); CountDownLatch knivLatch = new CountDownLatch(ANTALL_KNIVTRAADER); CountDownLatch saksLatch = new CountDownLatch(ANTALL_SAKSTRAADER); for (int i = 0; i < ANTALL_KNIVTRAADER; i++) { new Thread(new Knivprodusent(kMonitor, 3, knivLatch)).start(); } // try { // knivLatch.await(); // } catch (InterruptedException e) { // System.out.println("Avbrutt..."); // System.exit(-1); // } for (int i = 0; i < ANTALL_SAKSTRAADER; i++) { new Thread(new Saksprodusent(sMonitor, kMonitor, saksLatch)).start(); } try { knivLatch.await(); saksLatch.await(); } catch (InterruptedException e) { System.out.println("Avbrutt..."); System.exit(-1); } System.out.println("Antall kniver produsert: " + ANTALL_KNIVTRAADER * 3); System.out.println("Antall sakser produsert: " + sMonitor.antallSakser()); } }