Map<String, Context> requestContexts = this.contexts.get(Thread.currentThread());
if (requestContexts == null) {
requestContexts = new ConcurrentHashMap<String, Context>();
List<Context> shutdownQueue = new ArrayList<Context>();
for (ContextFactory<Context> config : contextFactories.values()) {
Context context = config.createContext();
context.start();
requestContexts.put(context.getName(), context);
}
// initialize eager components. Note this cannot be done when we initially create each context since a component may
// contain a forward reference to a component which has not been instantiated
for (Context context : requestContexts.values()) {
if (context instanceof AtomicContext) {
AtomicContext atomic = (AtomicContext) context;
if (atomic.isEagerInit()) {
atomic.init(); // Notify the instance
synchronized(shutdownQueue){
shutdownQueue.add(context);
}
}
}
context.addListener(this);
}
contexts.put(Thread.currentThread(), requestContexts);
destroyQueues.put(Thread.currentThread(), shutdownQueue);
}
return requestContexts;