/**
* Initial context.
*/
- protected static Context initialContext = null;
+ protected static volatile Context initialContext = null;
// --------------------------------------------------------- Public Methods
if ((ContextBindings.isThreadBound()) ||
(ContextBindings.isClassLoaderBound())) {
return new SelectorContext((Hashtable<String,Object>)environment);
- } else {
- return null;
}
+ return null;
}
// 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;
}