// HappyBirthday.javapublic class HappyBirthday { private static final Logger log = getLogger(HappyBirthday.class); static final String NAME = "Alex"; static final String FROM = "UIM colleagues"; public static void main(String[] args) throws Exception { var cake = new Cake(7); var candlesOut = new CountDownLatch(cake.size()); cake.onCandleOut(candle -> candlesOut.countDown()); log.info("Compiling wishes for {}", NAME); for (Candle c : cake.candles()) { c.light(); log.debug("Candle {}/{} lit", c.index() + 1, cake.size()); } log.info("All {} candles lit", cake.size()); log.info("Happy birthday, {}!", NAME); log.info("Signed by {}", FROM); candlesOut.await(); // park until the cake is dark log.info("Wish committed"); }}
// waiting for the first candle
application.log
stopped
// waiting for the JVM