From 18d1c0880fe6833db50d8e0b7fc54ce281a703b2 Mon Sep 17 00:00:00 2001 From: markt Date: Wed, 18 Nov 2009 23:54:24 +0000 Subject: [PATCH] Fix theorectical sync issue and soem Eclipse warnings git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@882008 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/naming/java/javaURLContextFactory.java | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/java/org/apache/naming/java/javaURLContextFactory.java b/java/org/apache/naming/java/javaURLContextFactory.java index 100ae9a2e..4425e3394 100644 --- a/java/org/apache/naming/java/javaURLContextFactory.java +++ b/java/org/apache/naming/java/javaURLContextFactory.java @@ -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)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)environment, true); - } else { - // If the thread is not bound, return a shared writable context - if (initialContext == null) - initialContext = new NamingContext( - (Hashtable)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)environment, MAIN); + } + } + } + return initialContext; } -- 2.11.0