import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Condition; import java.util.ArrayList; class Bord{ private ArrayList kopper = new ArrayList<>(); private Lock lock = new ReentrantLock(); private Condition ikkeTomt = lock.newCondition(); private int totaltAntallKopper; public Bord(int totaltAntallKopper){ this.totaltAntallKopper = totaltAntallKopper; } public void serverKaffe(String kaffe){ lock.lock(); try { kopper.add(kaffe); totaltAntallKopper--; ikkeTomt.signalAll(); } finally { lock.unlock(); } } public String hentKaffe() throws InterruptedException{ lock.lock(); try{ while (kopper.isEmpty() && totaltAntallKopper > 0){ ikkeTomt.await(); } if (!kopper.isEmpty()){ return kopper.remove(0); } return null; } finally { lock.unlock(); } } }