0

I have multiple producers, each pushing data into there own Blocking queues. The data from each producer is processed independently, (hence the separate queues).

My single consumer currently polls each of those queues, with a timeout on each.

Program works just fine, but I am trying to optimize, I don't like the "polling". Is this the most efficient way to approach this.?,

I have written the same app using a consumer per producer, but that profiled slightly worse.

thanks .

user3312154
  • 235
  • 3
  • 14
  • 1
    What does "processed independently" mean? – dlev Feb 15 '14 at 00:17
  • 2
    Could you show the code? – Emmanuel John Feb 15 '14 at 00:25
  • Even though each producer does its own processing, you should still be able to get away with all four producers pushing to the same queue, which the consumer simply consumes from. Am I correct each producer generates a completely different type of object? If so, do these objects inherit from a common class? – Paul Richter Feb 15 '14 at 00:52
  • You should investigate why multiple consumers perform worse: because of the consumer task size or because of the common number of threads in your program (more threads sometimes mean less performance). – krems Feb 15 '14 at 05:49

1 Answers1

1

Try to register the consumer as a listener on the queues, so that a change in the queue status informs the consumer without actively polling (Inversion of control).

Smutje
  • 17,733
  • 4
  • 24
  • 41