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/

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top