The producer - consumer pattern is quite famous. It's where a bunch of work items are 'produced' at a high rate which cannot be processed at the same rate usually because applying business-logic usually requires things like database lookups, CPU intensive calculations & other logic.
The usual way to deal with this is to use multiple threads. Now using multiple threads usually comes with its own idiosyncrasies like protecting shared data and others. When working in Java, using a blocking queue makes implementing this pattern really simple.
The idea is to have a piece of code let's call it the 'producer' which knows what work-items need to be processed store the work-items in a queue. A bunch of threads keep polling the queue for any work-item which is made available on the queue.
Using a blocking queue like the LinkedBlockingQueue allows you to do this easily as this class is thread safe i.e. the producer code can safely place items on the queue using the 'put' method. The consumer code can safely read items off the queue using the 'take' or 'poll' method. The 'take' method is a blocking method i.e. the thread will wait forever until an item is found on the queue. The 'poll' method allows you to specify a timeout so that if the queue doesn't contain any items, the method will return a null.
The implementation allows the main program to stop the producer and consumers by calling the 'signalStop' method. Since both the producer and the consumer would like this abiity to stop, this functionality is made available in the 'Stopable' class which is the base class of Producer and Consumer. The source code is given below: