Results 1 to 2 of 2
  1. #1
    zhackwyatt is offline Member
    Join Date
    Mar 2008
    Posts
    1
    Rep Power
    0

    Question 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?

  2. #2
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    6

    Default

    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

  1. Replies: 0
    Last Post: 04-09-2008, 06:41 PM
  2. Please wail Message in jsp
    By amar.java in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-02-2008, 12:29 PM
  3. How to brodcast a message in the LAN
    By Alpha in forum Networking
    Replies: 1
    Last Post: 05-20-2007, 04:07 PM
  4. About bean:message
    By yuchuang in forum Web Frameworks
    Replies: 1
    Last Post: 05-03-2007, 04:50 PM
  5. error message on jsp
    By sandor in forum Web Frameworks
    Replies: 1
    Last Post: 04-11-2007, 02:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •