September 2019
Intermediate to advanced
816 pages
18h 47m
English
Since the producers (checkers) and consumer (packers) don't work at the same time, we can easily fill up a queue with 15,000,000 bulbs via a trivial for loop (we are not very interested in this part of the assembly line). This is shown in the following code snippet:
private static final Random rnd = new Random();private static final int MAX_PROD_BULBS = 15_000_000;private static final BlockingQueue<String> queue = new LinkedBlockingQueue<>();...private static void simulatingProducers() { logger.info("Simulating the job of the producers overnight ..."); logger.info(() -> "The producers checked " + MAX_PROD_BULBS + " bulbs ..."); for (int i = 0; i < MAX_PROD_BULBS; i++) { queue.offer("bulb-" + rnd.nextInt(1000)); ...