Now I have a turn, with several manufacturers and one consumer.
Consumer flow is slow. In addition, the consumer takes the item from the queue through the peek operation, and until the consumption operation is completed, the item cannot be removed from the queue. This is due to the fact that the producer flow, as a side operation, also takes a snapshot of all the elements that are not fully processed at this point in time.
Now I want to change my code to support multiple consumers. So, let's say I have three threads, one thread will take the first element, which can be read through the peek operation. The second consumer thread can go to the second item, but I have no way to get this, because the queue does not support restoring the second item.
Thus, the option to use the standard ConcurrentLinkedQueue (which I'm using now) is missing.
I mean using a priority queue, but then I will have to associate with each element a flag that tells me if this element is already used by some thread or not.
Which data structure is most suitable for this problem?
source share