java BlockingQueue does not have a blocking peek?

前端 未结 8 1665
一向
一向 2020-12-15 15:37

I have a blocking queue of objects.

I want to write a thread that blocks till there is a object on the queue. Similar to the functionality provided by BlockingQueue.

8条回答
  •  一个人的身影
    2020-12-15 16:29

    Looks like BlockingQueue itself doesn't have the functionality you're specifying.

    I might try to re-frame the problem a little though: what would you do with objects you can't "process correctly"? If you're just leaving them in the queue, you'll have to pull them out at some point and deal with them. I'd reccommend either figuring out how to process them (commonly, if a queue.get() gives any sort of invalid or bad value, you're probably OK to just drop it on the floor) or choosing a different data structure than a FIFO.

提交回复
热议问题