import java.util.concurrent.CountDownLatch; class HeatTortillasTask implements Runnable { CountDownLatch l; public HeatTortillasTask(CountDownLatch latch) { l = latch; } @Override public void run() { try { // Vi venter f?rst p? at CountDownLatch har telt ned, deretter fortsetter vi... l.await(); System.out.println("Heating tortillas"); Thread.sleep((int) (Math.random() * 3000)); System.out.println("Tortillas heated!"); } catch (InterruptedException e) { System.err.println("Tortilla heating was interrupted while waiting for other tasks. Dinner is cancelled!"); System.exit(1); } } }