“Closing” a blocking queue

前端 未结 10 682
不思量自难忘°
不思量自难忘° 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

    Today I solved this problem using a wrapper object. Since the ComplexObject is too complex to subclass I wrapped the ComplexObject into ComplexObjectWrapper object. Then used ComplexObjectWrapper as the generic type.

    public class ComplexObjectWrapper {
    ComplexObject obj;
    }
    
    public class EndOfQueue extends ComplexObjectWrapper{}
    

    Now instead of BlockingQueue I did BlockingQueue

    Since I had control of both the Consumer and Producer this solution worked for me.

提交回复
热议问题