title: How to properly close a JMS connection?
body: <p>I am trying to use Spring's SingleConnectionFactory, where there are 2 connection factories, and only one of them should be able to connect at a time.</p>
  
  <pre><code>&lt;bean id="connectionFactory1" class="org.springframework.jms.connection.SingleConnectionFactory102"&gt;
      &lt;property name="targetConnectionFactory"&gt;
          &lt;bean class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter"&gt;
              &lt;property name="username" value="LOGIN" /&gt;
              &lt;property name="password" value="PASS" /&gt;
              &lt;property name="targetConnectionFactory"&gt;
                  &lt;bean class="com.tibco.tibjms.TibjmsQueueConnectionFactory"&gt;
                      &lt;constructor-arg value="URL" /&gt;
                      &lt;constructor-arg value="CLIENT_ID" /&gt;
                  &lt;/bean&gt;
              &lt;/property&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
      &lt;property name="reconnectOnException" value="true" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="connectionFactory2" class="org.springframework.jms.connection.SingleConnectionFactory102"&gt;
      &lt;property name="targetConnectionFactory"&gt;
          &lt;bean class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter"&gt;
              &lt;property name="username" value="LOGIN" /&gt;
              &lt;property name="password" value="PASS" /&gt;
              &lt;property name="targetConnectionFactory"&gt;
                  &lt;bean class="com.tibco.tibjms.TibjmsQueueConnectionFactory"&gt;
                      &lt;constructor-arg value="URL" /&gt;
                      &lt;constructor-arg value="CLIENT_ID" /&gt;
                  &lt;/bean&gt;
              &lt;/property&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
      &lt;property name="reconnectOnException" value="true" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>By using the same client id in both factories(CLIENT_ID), I made sure that when I create connection from one factory, I can't create another connection from the other factory (throws InvalidClientIDException, so this is as expected). But the issue is, when I close the connection I got from first factory, and try to get connection from second factory, I'm still getting the exception.</p>
  
  <p>Using the following Java code:</p>
  
  <pre><code>Connection connection1 = connectionFactory1.createConnection();
  connection1.close();
  
  Connection connection2 = connectionFactory2.createConnection();
  </code></pre>
  
  <p>What is the proper way of closing first connection, so that it allows me to create connection using the second factory?</p>
  
  <p>Also, note that I am not using Queues here. I have to achieve this without queues.</p>