I am trying to shut down my application ( which is a jar and is run manually)
I have read this : http://forum.spring.io/forum/spring-projects/container/98741-how-to-applicationcontext-memory-leaks-in-spring-3-0-x
Spring ApplicationContext - Resource leak: 'context' is never closed
and as i am using the spring 3.2.18
my code looks like
private static ConfigurableApplicationContext parentContext ;
private static ConfigurableApplicationContext processContext ;
private final String processApplicationContextChild; // filename: childContext.xml
public void run() {
log.debug("Loading parent context");
parentContext = new ClassPathXmlApplicationContext("applicationContext.xml") ;
parentContext.registerShutdownHook();
try {
runProcess(parentContext);
} catch (Throwable e) {
log.error("Unexpected error: " + e.getMessage(), e);
} finally {
log.info("Closing Core Context ");
if (parentContext.isActive()){
parentContext.close();
}
log.info("Core Closed");
}
}
protected void runProcess(ConfigurableApplicationContext parentContext) {
log.info("Loading " + Arrays.asList(processApplicationContextChild));
processContext = new ClassPathXmlApplicationContext(processApplicationContextChild, parentContext);
processContext.registerShutdownHook();
Runnable processor = (Runnable) processContext.getBean("processorRunnable", Runnable.class);
try {
processor.run();
} finally {
log.info("Closing child Context ");
processContext.close();
log.info(" Child Closed");
}
}
After the "Core Closed" is printed out. it just hangs and does nothing. I am expecting the JVM to exit.
There is some resource some where either the child or parent which is not closed properly. how can i view that resource. Or what could be the issue here. when i debug, on each .close() call, the context is still an instance with closed=true and isActive=false.
I even made them non static and used a try with resource block.