I’m using java.util.concurrent.BlockingQueue in a very simple producer-consumer scenario. E.g. this pseudo code depicts the consumer part:
class QueueCo
I have used this system:
ConsumerClass private boolean queueIsNotEmpty = true;//with setter ... do { ... sharedQueue.drainTo(docs); ... } while (queueIsNotEmpty || sharedQueue.isEmpty());
When producer finish, I set on consumerObject, queueIsNotEmpty field to false