Design pattern for 1 Producer/multiple Consumers?  
Author Message
ptomblin+netnews





PostPosted: 2007-9-28 7:24:00 Top

java-programmer, Design pattern for 1 Producer/multiple Consumers? I'm doing a simple Producer/Consumer thing based on the example in the Sun
docs, where the Consumer does a wait until there is something to consume,
then it consumes it and does a notify, and the Producer does a wait until
there is nothing to consume and then adds it and does a notify. But now I
need a bunch of Consumers. Is there a standard design pattern for this,
or am I going to have to figure it out myself?

--
Paul Tomblin <email***@***.com> http://blog.xcski.com/
Do you have a point, or are you saving it for a special occasion?
-- David P. Murphy
 
Patrick May





PostPosted: 2007-9-28 8:05:00 Top

java-programmer >> Design pattern for 1 Producer/multiple Consumers? ptomblin+email***@***.com (Paul Tomblin) writes:
> I'm doing a simple Producer/Consumer thing based on the example in
> the Sun docs, where the Consumer does a wait until there is
> something to consume, then it consumes it and does a notify, and the
> Producer does a wait until there is nothing to consume and then adds
> it and does a notify. But now I need a bunch of Consumers. Is
> there a standard design pattern for this, or am I going to have to
> figure it out myself?

This is a standard JavaSpaces' Master-Worker pattern. See
http://www.jini.org for general information on JavaSpaces and just
Google "javaspaces master worker" for numerous examples.

Regards,

Patrick

------------------------------------------------------------------------
S P Engineering, Inc. | Large scale, mission-critical, distributed OO
| systems design and implementation.
email***@***.com | (C++, Java, Common Lisp, Jini, middleware, SOA)
 
Hunter Gratzner





PostPosted: 2007-9-28 8:24:00 Top

java-programmer >> Design pattern for 1 Producer/multiple Consumers? On Sep 28, 1:24 am, ptomblin+email***@***.com (Paul Tomblin) wrote:
> I'm doing a simple Producer/Consumer thing based on the example in the Sun
> docs, where the Consumer does a wait until there is something to consume,
> then it consumes it and does a notify, and the Producer does a wait until
> there is nothing to consume and then adds it and does a notify. But now I
> need a bunch of Consumers.

http://java.sun.com/javase/6/docs/api/java/util/concurrent/BlockingQueue.html

pay special attention to the code example.

 
 
ptomblin+netnews





PostPosted: 2007-9-28 9:05:00 Top

java-programmer >> Design pattern for 1 Producer/multiple Consumers? In a previous article, Hunter Gratzner <email***@***.com> said:
>On Sep 28, 1:24 am, ptomblin+email***@***.com (Paul Tomblin) wrote:
>> there is nothing to consume and then adds it and does a notify. But now I
>> need a bunch of Consumers.
>
>http://java.sun.com/javase/6/docs/api/java/util/concurrent/BlockingQueue.html
>
>pay special attention to the code example.

I knew there was a reason why I liked Java 1.5.

Thanks.

--
Paul Tomblin <email***@***.com> http://blog.xcski.com/
When my ship comes in, I'll be waiting at the airport.
 
 
Lew





PostPosted: 2007-9-28 9:49:00 Top

java-programmer >> Design pattern for 1 Producer/multiple Consumers? Paul Tomblin wrote:
> In a previous article, Hunter Gratzner <email***@***.com> said:
>> On Sep 28, 1:24 am, ptomblin+email***@***.com (Paul Tomblin) wrote:
>>> there is nothing to consume and then adds it and does a notify. But now I
>>> need a bunch of Consumers.
>> http://java.sun.com/javase/6/docs/api/java/util/concurrent/BlockingQueue.html
>>
>> pay special attention to the code example.
>
> I knew there was a reason why I liked Java 1.5.

There are several idioms. /Java Concurrency in Practice/ by Brian Goetz, et
al., discusses a few of them.

--
Lew