So I have multiple steps stage 1 -> stage 2 -> stage 3 -> stage4 so in some cases the producer would be a consumer, and at each stage there are multiple producers/consumers to make use of multiple cpus. In case relevent some packets would miss out steps, i.e go straight from stage 1 to stage 4.
So I was going to have a class for each stage, sharing a BlockingQueue with the previous stage, but Ive also read that the ExecutorService works like a Producer/Consumer pattern all in one, so Im trying to go with the best abstraction.
However it seems to me that using an Executor, that the producer bit is done before they are submitted to the executor, in a sequential way which is not what I want.
Could anyone clarify please ?
Sounds like you need a java.util.concurrent.CompletionService
for each stage, instead of a BlockingQueue
.
Take a look on Executors and thread pools. Here is the official tutorial: http://download.oracle.com/javase/tutorial/essential/concurrency/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With