Results 1 to 2 of 2
- 03-24-2008, 03:17 AM #1Member
- Join Date
- Mar 2008
- Rep Power
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
- By Java Tip in forum java.langReplies: 0Last Post: 04-09-2008, 06:41 PM
- By amar.java in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 04-02-2008, 12:29 PM
- By Alpha in forum NetworkingReplies: 1Last Post: 05-20-2007, 04:07 PM
- By yuchuang in forum Web FrameworksReplies: 1Last Post: 05-03-2007, 04:50 PM
- By sandor in forum Web FrameworksReplies: 1Last Post: 04-11-2007, 02:10 AM