September 2019
Intermediate to advanced
816 pages
18h 47m
English
Instead of filling a queue with 15,000,000 bulbs, let's fill 15 queues with 1,000,000 bulbs each:
private static final int MAX_PROD_BULBS = 15 _000_000;private static final int CHUNK_BULBS = 1 _000_000;private static final Random rnd = new Random();private static final Queue<BlockingQueue<String>> chunks = new LinkedBlockingQueue<>();...private static Queue<BlockingQueue<String>> simulatingProducers() { logger.info("Simulating the job of the producers overnight ..."); logger.info(() -> "The producers checked " + MAX_PROD_BULBS + " bulbs ..."); int counter = 0; while (counter < MAX_PROD_BULBS) { BlockingQueue chunk = new LinkedBlockingQueue<>(CHUNK_BULBS); for (int i = 0; i < CHUNK_BULBS; i++) { chunk.offer("bulb-" ...