title: Maintaining a connection to server in thread?
body: <p>I'm not sure how to design my program to multi-thread better.  Basically I have a queue server that I connect to and send it work but as I launch more threads to send more work faster I notice my threads are blocking.</p>
  
  <p>Here's a example of what I'm doing(in my program I'm sending some data and a channel that is derived from a shared connection).</p>
  
  <pre><code>class Send_to_Queue implements Runnable{
  
      protected String queue_name = null;
      protected Channel channel = null;
      protected byte[] message = 0
  
     public Send_to_Queue(String queue_name, byte[] message, Channel channel) {
          // TODO Auto-generated constructor stub
          this.queue_name = queue_name;
          this.message   = message;
          this.channel = channel;         
      } 
  </code></pre>
  
  <p>The channel is not unique to the thread its shared by all the threads being launched which is where the blocking is coming from I think.  I'm just a bit confused on the best way to do this because I'm not sure how to get  <code>ThreadPoolExecutor</code> to create a new channel for the duration of its life and not create a new one(sort of expensive) with each task.  If there's no work I don't mind it shutting down but if I have 4 threads and 100 units of work I want it to establish a new channel only 4 times and not 100.</p>
  
  <p>I know the synax of creating new channels/connections to my server just don't seem to understand how to do it in a way that its not established upon every instance.  Passing the connection to a thread and having it starting a new channel(under <code>this.channel</code> is creating a new channel everytime)</p>