Results 1 to 2 of 2
- 03-24-2008, 03:17 AM #1
Member
- Join Date
- Mar 2008
- Posts
- 1
- Rep Power
- 0
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?
- 04-23-2008, 08:27 PM #2
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
Similar Threads
-
Implementation of the Producer/Consumer problem in Java
By Java Tip in forum java.langReplies: 0Last Post: 04-09-2008, 06:41 PM -
Please wail Message in jsp
By amar.java in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 04-02-2008, 12:29 PM -
How to brodcast a message in the LAN
By Alpha in forum NetworkingReplies: 1Last Post: 05-20-2007, 04:07 PM -
About bean:message
By yuchuang in forum Web FrameworksReplies: 1Last Post: 05-03-2007, 04:50 PM -
error message on jsp
By sandor in forum Web FrameworksReplies: 1Last Post: 04-11-2007, 02:10 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks