【问题标题】:Spring ApplicationContext.close() doesnot shut down applicationSpring ApplicationContext.close() 不会关闭应用程序
【发布时间】:2019-01-08 17:04:35
【问题描述】:

我正在尝试关闭我的应用程序(这是一个 jar 并且手动运行)

我已阅读: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

因为我使用的是 spring 3.2.18

我的代码看起来像

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");
        }
    }

“Core Closed”打印出来后。它只是挂起,什么也不做。我期待 JVM 退出。

在某些资源中,子资源或父资源未正确关闭。我如何查看该资源。或者这里可能是什么问题。 当我调试时,在每个 .close() 调用中,上下文仍然是一个 close=true 和 isActive=false 的实例。

我什至使它们成为非静态的,并尝试使用资源块。

【问题讨论】:

    标签: java spring


    【解决方案1】:

    问题是资源泄漏,此处描述了解决方案 RestEasyClient JAX RS possible resource leak if not done correctly

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-27
      • 2015-07-03
      • 2012-06-30
      • 1970-01-01
      • 2019-01-27
      相关资源
      最近更新 更多