0

I'm looking for a queue data structure which supports the following:

  • Given items with (ID, value) it should contain only the newest values for a given ID. E.g. if there is an item with ID 5 and value "a" in the queue not yet consumed and the new item with ID 5 and value "b" is added to the queue, the old item with value "a" must be discarded.

  • items must be rate limited per second. E.g. at most one item with ID 6 must be available for consuming

  • the data structure is thread safe as it will have multiple consumers from different threads

  • the data structure must support high throughput ideally 1 000 000 incoming messages per second

I have tried a combination of concurrent hash map with a queue and wonder if there might be a better solution

Urb
  • 1
  • You should review the _[ConcurrentLinkedDeque](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/util/concurrent/ConcurrentLinkedDeque.html)_ class, although I don't believe you can replace items. There is also the _[LinkedHashMap](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/util/LinkedHashMap.html)_, with the exception that it's not intrinsically thread-safe. On that note, just review the entire _[Collections](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/util/package-summary.html)_ framework. – Reilas Jun 09 '23 at 00:17

0 Answers0