class CookMeatTask implements Runnable { @Override public void run() { try { System.out.println("Cooking meat"); Thread.sleep((int) (Math.random() * 5000)); System.out.println("Meat cooked!"); } catch (InterruptedException e) { System.err.println("Meat cooking was interrupted. Dinner is cancelled!"); System.exit(1); } } }