简体   繁体   English

PayaraMicro 不会在 EJB 或 ApplicationScoped 上调用 @PreDestroy

[英]PayaraMicro does not call @PreDestroy on EJB or ApplicationScoped

I'm migrating a WAR application from PayaraServer to Payara Micro to reduce RAM usage.我正在将一个 WAR 应用程序从 PayaraServer 迁移到 Payara Micro 以减少 RAM 使用量。

I just realise that @PreDestroy on EJBs are not called when stopping the instance with CTRL+C.我只是意识到在使用 CTRL+C 停止实例时不会调用 EJB 上的 @PreDestroy。

Is there a correct way to close the payaramicro instance properly as I'd like to execute some operations.是否有正确的方法可以正确关闭 payaramicro 实例,因为我想执行一些操作。

Thanks for your answers!感谢您的回答!

Or which services in Payara Server to deactivate to use as much as RAM as PayaraMicro?或者要停用 Payara Server 中的哪些服务以使用与 PayaraMicro 一样多的 RAM?

I'm using the version 5.183, and I also tried the 5.192.我使用的是 5.183 版本,我也尝试了 5.192。

Which kind of EJB did you use?你用的是哪种EJB? In my opinion it should work on @Singleton and @Stateless .在我看来,它应该适用于@Singleton@Stateless I am not sure how the other EJBs are supported by Payara Micro.我不确定 Payara Micro 是如何支持其他 EJB 的。

However, since Payara Micro supports the Java EE Web Profile and you are using a web application anyway, I would suggest to use a @WebListener to get notified of lifecycle events.但是,由于 Payara Micro 支持 Java EE Web Profile 并且您无论如何都在使用 Web 应用程序,因此我建议使用@WebListener来获取生命周期事件的通知。

It could be implemented as follows:它可以实现如下:

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class ContextListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent event) {
        // do needed setup work here
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
        // do your cleanup actions here
    }
}

Simply add this class to your WAR file then.只需将此类添加到您的 WAR 文件中即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM