title: javax.jms.IllegalStateException: The Session is closed
body: <p>I have different problems with a Camel Producer that I tried to solved but I've fallen into other problems.</p>
  
  <p>1) The first implementation I did was to create a producer template each time we needed to communicate with an ActiveMQ topic. That resulted with poor memory results leading to server crashing after sometime.</p>
  
  <p>The solution for the memory problem was to stop() producer template after each request. That fix has corrected the memory issue but cause some latency problem. </p>
  
  <p>2) I read somewhere that it's not necessary to create each time a producer template. So I decide to fix the latency problem and declared only one producer template in my class and use it for each request. It seem to work fine, no memory leak, fix the latency problem... </p>
  
  <p>BUT, when we send multiple queries that take a lot of time (20 sec each), it looks like we hit a timeout and the component crash with something like «<strong><em>javax.jms.IllegalStateException: The Session is closed</em></strong>».</p>
  
  <p><strong>Is there a way to do multi threading? Is this cause by using InOut exchange pattern? How the MAXIMUM_CACHE_POOL_SIZE works? Is my implementation is right?</strong></p>
  
  <p>I've put a sample of the code of my component:</p>
  
  <pre><code>public void process(Exchange exchange) throws Exception 
  {        
      Message in = exchange.getIn(); 
  
      if (producerTemplate == null) {            
          CamelContext camelContext = exchange.getContext();
          //camelContext.getProperties().put(Exchange.MAXIMUM_CACHE_POOL_SIZE, "50");
          producerTemplate = camelContext.createProducerTemplate();
      }
  
      ...
      result = producerTemplate.sendBody(String.format("activemq:%s", camelContext.resolvePropertyPlaceholders("{{channel1}}")), ExchangePattern.InOut, messageToSend).toString(); 
  
      ...
      finalResult = producerTemplate.sendBody(String.format("activemq:%s", camelContext.resolvePropertyPlaceholders("{{channel2}}")), ExchangePattern.InOut, result).toString(); 
  
      ...
      in.setBody(finalResult );
  }
  </code></pre>