[jboss-cvs] JBoss Messaging SVN: r6307 - in trunk/examples/jms/transactional: src/org/jboss/jms/example and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Apr 3 12:43:22 EDT 2009


Author: gaohoward
Date: 2009-04-03 12:43:22 -0400 (Fri, 03 Apr 2009)
New Revision: 6307

Modified:
   trunk/examples/jms/transactional/readme.html
   trunk/examples/jms/transactional/src/org/jboss/jms/example/TransactionalExample.java
Log:
close initial context


Modified: trunk/examples/jms/transactional/readme.html
===================================================================
--- trunk/examples/jms/transactional/readme.html	2009-04-03 16:39:25 UTC (rev 6306)
+++ trunk/examples/jms/transactional/readme.html	2009-04-03 16:43:22 UTC (rev 6307)
@@ -16,7 +16,7 @@
      <ol>
         <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li>
         <pre>
-           <code>InitialContext initialContext = getContext();</code>
+           <code>initialContext = getContext();</code>
         </pre>
 
         <li>We look-up the JMS queue object from JNDI</li>
@@ -103,18 +103,23 @@
         </pre>
 
 
-	<li>And finally (no pun intended), <b>always</b> remember to close your JMS connections after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its session, consumer, producer and browser objects</li>
+	<li>And finally (no pun intended), <b>always</b> remember to close your JMS connections after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its session, consumer, producer and browser objects. Also remember to close the initial context</li>
 
         <pre>
            <code>
 
       finally
       {
-         if (connection != null)
+         if(connection != null)
          {
-            // Be sure to close our JMS resources!
+            // Step 18. Be sure to close our JMS resources!
             connection.close();
          }
+         if(initialContext != null)
+         {
+            // Step 19. Also close initial context!
+            initialContext.close();
+         }
       }
            </code>
         </pre>

Modified: trunk/examples/jms/transactional/src/org/jboss/jms/example/TransactionalExample.java
===================================================================
--- trunk/examples/jms/transactional/src/org/jboss/jms/example/TransactionalExample.java	2009-04-03 16:39:25 UTC (rev 6306)
+++ trunk/examples/jms/transactional/src/org/jboss/jms/example/TransactionalExample.java	2009-04-03 16:43:22 UTC (rev 6307)
@@ -23,7 +23,6 @@
 
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
-import javax.jms.JMSException;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
 import javax.jms.Queue;
@@ -46,10 +45,11 @@
    public void runExample() throws Exception
    {
       Connection connection = null;
+      InitialContext initialContext = null;
       try
       {
          // Step 1. Create an initial context to perform the JNDI lookup.
-         InitialContext initialContext = getContext();
+         initialContext = getContext();
 
          // Step 2. Look-up the JMS topic
          Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
@@ -125,16 +125,14 @@
       {
          if(connection != null)
          {
-            try
-            {
-               // Step 18. Be sure to close our JMS resources!
-               connection.close();
-            }
-            catch (JMSException e)
-            {
-               e.printStackTrace();
-            }
+            // Step 18. Be sure to close our JMS resources!
+            connection.close();
          }
+         if(initialContext != null)
+         {
+            // Step 19. Also close initial context!
+            initialContext.close();
+         }
       }
    }
 




More information about the jboss-cvs-commits mailing list