Anonymous avatar Anonymous committed c2cf327

Issue number: QUARTZ-260, QUARTZ-259
Obtained from:
Submitted by:
Reviewed by:
CVS: ----------------------------------------------------------------------
CVS: Issue number:
CVS: If this change addresses one or more issues,
CVS: then enter the issue number(s) here.
CVS: Obtained from:
CVS: If this change has been taken from another system,
CVS: then name the system in this line, otherwise delete it.
CVS: Submitted by:
CVS: If this code has been contributed to the project by someone else; i.e.,
CVS: they sent us a patch or a set of diffs, then include their name/email
CVS: address here. If this is your work then delete this line.
CVS: Reviewed by:
CVS: If we are doing pre-commit code reviews and someone else has
CVS: reviewed your changes, include their name(s) here.
CVS: If you have not had it reviewed then delete this line.

git-svn-id: http://svn.opensymphony.com/svn/quartz/trunk@264 69f7d36a-ea1c-0410-88ea-9fd03e4c9665

Comments (0)

Files changed (4)

src/java/org/quartz/ee/jta/JTAJobRunShellFactory.java

  */
 package org.quartz.ee.jta;
 
-import javax.naming.InitialContext;
-
 import org.quartz.Scheduler;
 import org.quartz.SchedulerConfigException;
 import org.quartz.core.JobRunShell;
 
     private SchedulingContext schedCtxt;
 
-    private InitialContext initCtxt;
-
     private UserTransactionHelper userTxHelper;
 
     /*

src/java/org/quartz/jobs/ee/ejb/EJBInvokerJob.java

         } catch (NamingException ne) {
             throw new JobExecutionException(ne);
         }
-
+             
         Object value = null;
-
+        
         // locate home interface
         try {
             value = jndiContext.lookup(ejb);
         } catch (NamingException ne) {
             throw new JobExecutionException(ne);
+        } finally {
+            if (jndiContext != null) {
+                try {
+                    jndiContext.close();
+                } catch (NamingException e) {
+                    // Ignore any errors closing the initial context
+                }
+            }
         }
 
         // get home interface

src/java/org/quartz/utils/JNDIConnectionProvider.java

     private void init() {
 
         if (!isAlwaysLookup()) {
+            Context ctx = null;
             try {
-                Context ctx = null;
                 if (props != null) ctx = new InitialContext(props);
                 else
                     ctx = new InitialContext();
                 getLog().error(
                         "Error looking up datasource: " + e.getMessage(), e);
             }
+            finally {
+                if(ctx != null)
+                    try { ctx.close(); } catch(Exception ignore) {}
+            }
         }
     }
 
     public Connection getConnection() throws SQLException {
+        Context ctx = null;
         try {
             Object ds = this.datasource;
 
             if (ds == null || isAlwaysLookup()) {
-                Context ctx = null;
                 if (props != null) ctx = new InitialContext(props);
                 else
                     ctx = new InitialContext();
                     "Could not retrieve datasource via JNDI url '" + url + "' "
                             + e.getClass().getName() + ": " + e.getMessage());
         }
+        finally {
+            if(ctx != null)
+                try { ctx.close(); } catch(Exception ignore) {}
+        }
     }
 
     public boolean isAlwaysLookup() {

src/jboss/org/quartz/ee/jmx/jboss/QuartzService.java

     }
 
     private void rebind() throws Exception {
-        InitialContext rootCtx = new InitialContext();
-
-        // Get the parent context into which we are to bind
-        Name fullName = rootCtx.getNameParser("").parse(jndiName);
-
-        Name parentName = fullName;
-
-        if (fullName.size() > 1) {
-            parentName = fullName.getPrefix(fullName.size() - 1);
-        } else {
-            parentName = new CompositeName();
+        
+        InitialContext rootCtx = null;
+        
+        try {
+            rootCtx = new InitialContext();
+    
+            // Get the parent context into which we are to bind
+            Name fullName = rootCtx.getNameParser("").parse(jndiName);
+    
+            Name parentName = fullName;
+    
+            if (fullName.size() > 1) {
+                parentName = fullName.getPrefix(fullName.size() - 1);
+            } else {
+                parentName = new CompositeName();
+            }
+    
+            Context parentCtx = createContext(rootCtx, parentName);
+            Name atomName = fullName.getSuffix(fullName.size() - 1);
+            String atom = atomName.get(0);
+    
+            Scheduler scheduler = schedulerFactory.getScheduler();
+    
+            NonSerializableFactory.rebind(parentCtx, atom, scheduler);
+        }
+        finally {
+            if(rootCtx != null) try { rootCtx.close(); } catch(Exception ignore) {} 
         }
-
-        Context parentCtx = createContext(rootCtx, parentName);
-        Name atomName = fullName.getSuffix(fullName.size() - 1);
-        String atom = atomName.get(0);
-
-        Scheduler scheduler = schedulerFactory.getScheduler();
-
-        NonSerializableFactory.rebind(parentCtx, atom, scheduler);
     }
 
     private void unbind(String jndiName) throws NamingException {
-        Context rootCtx = new InitialContext();
-
-        Name fullName = rootCtx.getNameParser("").parse(jndiName);
-        Name atomName = fullName.getSuffix(fullName.size() - 1);
-        String atom = atomName.get(0);
-
-        rootCtx.unbind(jndiName);
-        NonSerializableFactory.unbind(atom);
+        InitialContext rootCtx = null;
+        
+        try {
+            rootCtx = new InitialContext();
+
+            Name fullName = rootCtx.getNameParser("").parse(jndiName);
+            Name atomName = fullName.getSuffix(fullName.size() - 1);
+            String atom = atomName.get(0);
+    
+            rootCtx.unbind(jndiName);
+            NonSerializableFactory.unbind(atom);
+        }
+        finally {
+            if(rootCtx != null) try { rootCtx.close(); } catch(Exception ignore) {} 
+        }
     }
 
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.