Fix theorectical sync issue and soem Eclipse warnings
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 18 Nov 2009 23:54:24 +0000 (23:54 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 18 Nov 2009 23:54:24 +0000 (23:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@882008 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/naming/java/javaURLContextFactory.java

index 100ae9a..4425e33 100644 (file)
@@ -66,7 +66,7 @@ public class javaURLContextFactory
     /**
      * Initial context.
      */
-    protected static Context initialContext = null;
+    protected static volatile Context initialContext = null;
 
 
     // --------------------------------------------------------- Public Methods
@@ -84,9 +84,8 @@ public class javaURLContextFactory
         if ((ContextBindings.isThreadBound()) || 
             (ContextBindings.isClassLoaderBound())) {
             return new SelectorContext((Hashtable<String,Object>)environment);
-        } else {
-            return null;
         }
+        return null;
     }
 
 
@@ -100,13 +99,18 @@ public class javaURLContextFactory
             // Redirect the request to the bound initial context
             return new SelectorContext(
                     (Hashtable<String,Object>)environment, true);
-        } else {
-            // If the thread is not bound, return a shared writable context
-            if (initialContext == null)
-                initialContext = new NamingContext(
-                        (Hashtable<String,Object>)environment, MAIN);
-            return initialContext;
         }
+
+        // If the thread is not bound, return a shared writable context
+        if (initialContext == null) {
+            if (initialContext == null) {
+                synchronized(this) {
+                    initialContext = new NamingContext(
+                            (Hashtable<String,Object>)environment, MAIN);
+                }
+            }
+        }
+        return initialContext;
     }