Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

Design pattern for 1 Producer/multiple Consumers?

Thread view: 
Paul Tomblin - 28 Sep 2007 00:24 GMT
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?

Signature

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

Patrick May - 28 Sep 2007 01:04 GMT
> 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
[quoted text clipped - 3 lines]
> 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.
         pjm@spe.com  | (C++, Java, Common Lisp, Jini, middleware, SOA)
Hunter Gratzner - 28 Sep 2007 01:24 GMT
> 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.
Paul Tomblin - 28 Sep 2007 02:04 GMT
In a previous article, Hunter Gratzner <a24900@googlemail.com> said:
>> 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.

Signature

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

Lew - 28 Sep 2007 02:49 GMT
> In a previous article, Hunter Gratzner <a24900@googlemail.com> said:
>>> there is nothing to consume and then adds it and does a notify.  But now I
[quoted text clipped - 4 lines]
>
> 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.

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.