Best way to implement a multiple producer / consumer pattern in Java 6

So, I have several stages, stage 1 โ†’ stage 2 โ†’ stage 3 โ†’ stage4, so in some cases the manufacturer will be a consumer, and at each stage several manufacturers / consumers can use several processors. In case it is appropriate that some packages will skip steps, that is, go from stage 1 to stage 4.

So, I had a class for each step that shared BlockingQueue in the previous step, but I also read that the ExecutorService works as a Producer / Consumer pattern, all in one, so Im trying to go with a better abstraction.

However, it seems to me that using the Contractor, that the producer bit is executed before they are sent to the artist, in a sequential manner, which is not what I want.

Can someone please clarify?

+5
source share
2 answers

It seems like you need java.util.concurrent.CompletionServicefor each stage instead BlockingQueue.

+1
source

Take a look at performers and thread pools. Here is the official tutorial: http://download.oracle.com/javase/tutorial/essential/concurrency/

+1
source

All Articles