6

I need to write my own version of a bounded queue. It must be thread safe. The consumption of this queue is based on a priority system, where a consumer makes a request for an object in the queue.

The queue can have many producers and many consumers. Consumers come and register their requests based on a certain criteria around the object. When an objects is put on the queue, the Consumers who register the request first should get priority to receive the object. If a consumer thread tries to get an object it has registered an interest in but that object is not there, then the consumer blocks until the producer puts the object in and notifies the consumer.

I have made my attempt below, but my implementation so far is just an ArrayBlockingQueue implementation. it doesn't cover the registering of types of objects.

https://stackoverflow.com/questions/40533143/single-producer-multiple-consumer-queue-contains-null

Do I need some sort of observer pattern?

TheCoder
  • 179
  • 2
  • *"I need to write my own version of a bounded queue"*: why? – Arseni Mourzenko Nov 11 '16 at 12:24
  • 3
    @ArseniMourzenko - I am learning multithreading and this is a task I have been given as a way to understand concurrency. – TheCoder Nov 11 '16 at 12:45
  • 1
    Well, what makes you think you need an Observer Pattern? Is there a problem to be solved here for which the Observer Pattern is uniquely suited? – Robert Harvey Nov 12 '16 at 18:38
  • @RobertHarvey - this bit: register their requests based on a certain criteria around the object. When an objects is put on the queue, the Consumers who register the request first should get priority to receive the object - sounds like a listener to me. – TheCoder Nov 12 '16 at 23:13

0 Answers0