“Closing” a blocking queue

前端 未结 10 680
不思量自难忘°
不思量自难忘° 2021-01-30 09:13

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         


        
10条回答
  •  失恋的感觉
    2021-01-30 09:53

    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

提交回复
热议问题