import java.util.Random; public class BrusMain { private static final int NUM_BUYERS = 3; private static final int NUM_SODAS_PER_BUYER = 5; private static final int SODAS_PER_REFILL = 5; private static final int NUM_REFILLS = (NUM_BUYERS * NUM_SODAS_PER_BUYER) / SODAS_PER_REFILL; private static final int MAX_BUYER_SLEEP = 5000; private static final int MAX_REFILL_SLEEP = 3000; private static final Random random = new Random(12345); public static void main(String[] args) { BrusMaskin bm = new BrusMaskin(SODAS_PER_REFILL); Runnable kjoper = new Runnable() { public void run(){ for(int i = 0; i < NUM_SODAS_PER_BUYER; i++){ try{ Thread.sleep(Math.abs(random.nextInt()) % MAX_BUYER_SLEEP); }catch (InterruptedException e){ } bm.kjopBrus(); } } }; for(int i = 0; i < NUM_BUYERS; i++){ new Thread(kjoper).start(); } new Thread(new Runnable(){ public void run(){ for(int i = 0; i < NUM_REFILLS; i++){ try{ Thread.sleep(Math.abs(random.nextInt()) % MAX_REFILL_SLEEP); }catch(InterruptedException e){ } bm.fyllpaa(); } } }).start(); } /* Lambda-funksjonen over er en kortform av f?lgende: Runnable dndj = new Runnable(); Thread jddj = new Thread(dndj); jddj.start(); */ }