Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-24-2008, 04:17 AM
Member
 
Join Date: Mar 2008
Posts: 1
zhackwyatt is on a distinguished road
One Producer - Many Consumers - Same Message
I hope this hasn't been asked before, but every time I search I never find help for my specific problem.

I have a program that does the following. Has one incoming TCP connection. Has many outgoing TCP connections. Each connection is in a separate thread. When I receieve a new string from the incoming I want to send it to all outgoing connections.

Currently I am just a Variable that gets overwritten w/ each new incoming message. I am afraid that it will get overwritten before it is sent on all outgoing connections. So I want to use a queue. However, and this is what I see in examples all over the web, once the outgoing pops from the queue, the other ones don't have that message anymore. So how do I pop it off once all consumer threads send the message off?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-23-2008, 09:27 PM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 110
danielstoner is on a distinguished road
There are lots of possible solutions, here are a couple:

- Keep a counter of remaining outgoing directions with each message in the queue and each outgoing thread will decrement it. Last thread removes it.

- Duplicate the message for each outgoing thread; one queue per thread.

Don't forget to synchronize in the proper places.
__________________
Daniel @ [www.littletutorials.com]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementation of the Producer/Consumer problem in Java Java Tip java.lang 0 04-09-2008 07:41 PM
Please wail Message in jsp amar.java JavaServer Pages (JSP) and JSTL 1 04-02-2008 01:29 PM
How to brodcast a message in the LAN Alpha Networking 1 05-20-2007 05:07 PM
About bean:message yuchuang Web Frameworks 1 05-03-2007 05:50 PM
error message on jsp sandor Web Frameworks 1 04-11-2007 03:10 AM


All times are GMT +3. The time now is 08:08 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org