Concurrent Set Queue

前端 未结 7 1676
情话喂你
情话喂你 2020-12-05 23:10

Maybe this is a silly question, but I cannot seem to find an obvious answer.

I need a concurrent FIFO queue that contains only unique values. Attempting to add a val

7条回答
  •  佛祖请我去吃肉
    2020-12-05 23:31

    There's not a built-in collection that does this. There are some concurrent Set implementations that could be used together with a concurrent Queue.

    For example, an item is added to the queue only after it was successfully added to the set, and each item removed from the queue is removed from the set. In this case, the contents of the queue, logically, are really whatever is in the set, and the queue is just used to track the order and provide efficient take() and poll() operations found only on a BlockingQueue.

提交回复
热议问题