}
// shutdown destroyable instances in reverse instantiation order
ListIterator<Context> iter = destroyQueue.listIterator(destroyQueue.size());
synchronized (destroyQueue) {
while (iter.hasPrevious()) {
Lifecycle context = iter.previous();
if (context.getLifecycleState() == RUNNING) {
try {
if (context instanceof AtomicContext) {
((AtomicContext) context).destroy();
}
} catch (TargetException e) {
// TODO send a monitoring event
}
}
}
}
// shutdown contexts
Map<String, Context> currentContexts = contexts.remove(Thread.currentThread());
if (currentContexts == null) {
return;
}
for (Lifecycle context : currentContexts.values()) {
if (context.getLifecycleState() == RUNNING) {
context.stop();
}
}
}