[jboss-cvs] JBoss Messaging SVN: r6305 - in trunk/examples/jms/temp-queue: 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:38:28 EDT 2009


Author: gaohoward
Date: 2009-04-03 12:38:28 -0400 (Fri, 03 Apr 2009)
New Revision: 6305

Modified:
   trunk/examples/jms/temp-queue/readme.html
   trunk/examples/jms/temp-queue/src/org/jboss/jms/example/TemporaryQueueExample.java
Log:
close initial context


Modified: trunk/examples/jms/temp-queue/readme.html
===================================================================
--- trunk/examples/jms/temp-queue/readme.html	2009-04-03 16:32:31 UTC (rev 6304)
+++ trunk/examples/jms/temp-queue/readme.html	2009-04-03 16:38:28 UTC (rev 6305)
@@ -15,7 +15,7 @@
      <ol>
         <li>First we need to get an initial context so we can look-up the JMS connection factory 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 JMS connection factory from JNDI</li>
@@ -114,7 +114,7 @@
            </code>
         </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>
@@ -123,9 +123,14 @@
       {
          if (connection != null)
          {
-            // Be sure to close our JMS resources!
+            //Step 20. Be sure to close our JMS resources!
             connection.close();
          }
+         if (initialContext != null)
+         {
+            //Step 21. Also close the initialContext!
+            initialContext.close();
+         }
       }
            </code>
         </pre>

Modified: trunk/examples/jms/temp-queue/src/org/jboss/jms/example/TemporaryQueueExample.java
===================================================================
--- trunk/examples/jms/temp-queue/src/org/jboss/jms/example/TemporaryQueueExample.java	2009-04-03 16:32:31 UTC (rev 6304)
+++ trunk/examples/jms/temp-queue/src/org/jboss/jms/example/TemporaryQueueExample.java	2009-04-03 16:38:28 UTC (rev 6305)
@@ -24,7 +24,6 @@
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
 import javax.jms.InvalidDestinationException;
-import javax.jms.JMSException;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
@@ -47,10 +46,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 connection factory
          ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
@@ -125,16 +125,14 @@
       {
          if(connection != null)
          {
-            try
-            {
-               // Step 20. Be sure to close our JMS resources!
-               connection.close();
-            }
-            catch (JMSException e)
-            {
-               e.printStackTrace();
-            }
+            // Step 20. Be sure to close our JMS resources!
+            connection.close();
          }
+         if (initialContext != null)
+         {
+            //Step 21. Also close the initialContext!
+            initialContext.close();
+         }
       }
    }
 }




More information about the jboss-cvs-commits mailing list