title: How should I handle Multi-threading in Java?
body: <p>I am working on a practical scenario related with Java;a socket program. The existing system and the expected system are as follows.</p>
  
  <p><strong>Existing System</strong> - The system checks that a certain condition is satisfied. If so It will create some message to be sent and put it into a queue. </p>
  
  <p>The queue processor is a separate thread. It periodically check the queue for existence of items in it. If found any items (messages) it just sends the message to a remote host (hardcoded) and remove the item from queue.</p>
  
  <p><strong>Expected System</strong> - This is something like that. The message is created when a certain condition is satisfied but in every case the recipient is not same. So there are many approaches. </p>
  
  <ol>
  <li><p>putting the message into the same queue but with its receiver ID. In this case the 2nd thread can identify the receiver so the message can be sent to that.</p></li>
  <li><p>Having multiple threads. In this case when the condition is satisfied and if the receiver in "New" it creates a new queue and put the message into that queue. And a new thread initializes to process that queue. If the next messages are directed to same recipient it should put to the same queue and if not a new queue and the thread should be created.</p></li>
  </ol>
  
  <p>Now I want to implement the 2nd one, bit stucked. How should I do that? A skeleton would be sufficient and you won't need to worry to put how to create queues etc... :)</p>
  
  <p>Update : I also think that the approach 1 is the best way to do that. I read some articles on threading and came to that decision. But it is really worth to learn how to implement the approach 2 as well.</p>