[jboss-cvs] JBoss Messaging SVN: r6304 - in trunk/examples/jms/durable: 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:32:32 EDT 2009


Author: gaohoward
Date: 2009-04-03 12:32:31 -0400 (Fri, 03 Apr 2009)
New Revision: 6304

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


Modified: trunk/examples/jms/durable/readme.html
===================================================================
--- trunk/examples/jms/durable/readme.html	2009-04-03 16:23:33 UTC (rev 6303)
+++ trunk/examples/jms/durable/readme.html	2009-04-03 16:32:31 UTC (rev 6304)
@@ -112,7 +112,7 @@
            <code>session.unsubscribe("subscriber-1");</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 JNDI initial context.</li>
 
         <pre>
            <code>
@@ -121,9 +121,14 @@
       {
          if (connection != null)
          {
-            // Be sure to close our JMS resources!
+            //Step 19. Be sure to close our JMS resources!
             connection.close();
          }
+         if (initialContext != null)
+         {
+            //Step 20. Also close the initialContext!
+            initialContext.close();
+         }
       }
            </code>
         </pre>
@@ -132,4 +137,4 @@
          
      </ol>
   </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/examples/jms/durable/src/org/jboss/jms/example/DurableSubscriberExample.java
===================================================================
--- trunk/examples/jms/durable/src/org/jboss/jms/example/DurableSubscriberExample.java	2009-04-03 16:23:33 UTC (rev 6303)
+++ trunk/examples/jms/durable/src/org/jboss/jms/example/DurableSubscriberExample.java	2009-04-03 16:32:31 UTC (rev 6304)
@@ -45,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
          Topic topic = (Topic)initialContext.lookup("/topic/exampleTopic");
@@ -122,6 +123,11 @@
             // Step 19. Be sure to close our JMS resources!
             connection.close();
          }
+         if (initialContext != null)
+         {
+            //Step 20. Also close the initialContext!
+            initialContext.close();
+         }
       }
    }
 }




More information about the jboss-cvs-commits mailing list